简体   繁体   中英

Android - How to test onResume()?

I'd like a way to easily take an app and put it into a saved state mode (on an actual device) so that I can resume the app and thus test the onResume function. On android devices, when one exists an app, it does not instantly save its state; instead, it keeps the app running for quite a while in case you decide to return to it shortly. This causes the onResume function to not actually be called. Instead of having to wait that long period of time with the app out of focus before the OS decides to save its state, I'd like a way to quickly tell the OS to do this. Any suggestions?

If you delve into your phone's Settings, under Developer Options, you'll see an option right at the bottom under the "Apps" heading:

Don't keep activities
Destroy every activity as soon as the user leaves it

Try enabling that option and see if it gives you what you want.

(The above applies to Jelly Bean; I don't know if the same option was present on earlier versions.)

If you look at an Activitys lifecircle, you'll see that the onResume also is called when you start an activity.

http://www.android-app-market.com/wp-content/uploads/2012/03/Android-Activity-Lifecycle.png

If you would like to see how you onResume method is processing, then you should set a Break point, and then just start the activity in debug mode.

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