简体   繁体   中英

Maintaining application state in Android

I'm trying to guess why, if I open my application, lock the device and some hours later resume the activity it crashes. I suppose thats why, after some time, Android destroy my app and then tries to resume and im not saving correctly the state of my activities.

How can I force Android to destroy my app as it does usually without having to wait hours?

Thanks in advance

You have both an onCreate() and onResume() method available to you as well as onPause() and onDestroy(). If you manage the life cycle properly with those methods (life cycle detailed here ) you should be able to eliminate the crash.

I'm guessing you do some setup in the onCreate() method that you should really be doing in onResume().

You can use Development tools:

http://developer.android.com/guide/developing/debugging/debugging-devtools.html

Note the feature "Immediately destroy activities". You should be able to use it in android emulators.

If you finish( ) your Activities and stop your services the process should be finished.

Of course is someone presses the menu button your activities will only be paused and not finished() 'd and when you come back their state may have been taken for other memory which you should check for when they come back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM