简体   繁体   中英

OnPause() not called when relaunch activity in emulator

I've chosen to save the persistent application state in the OnPause() method to my database because OnPause() is guaranteed to be called before the application gets killed according to the documentation of the activity life cycle .

Now I am facing following behaviour using eclipse and avd emulator (api level 8):
1. I start my application via eclipse - Instance1
2. I start my application via eclipse again - Instance2

Now Instance1 is being terminated without calling OnPause() !

Could somebody please explain me why OnPause() is not being called? I thought it is guaranteed to be called always. If this is not the case, maybe because of the way eclipse terminates Instance1 process, then I would like to know if I could change this. Thanks a lot.

When you start the application via eclipse, it will effectively rip the rug out from any instance of the same app already running on the device or an emulator. This will never happen in practice, only when running from eclipse.

So you can plan on onPause() always being called.

what you mean you start application via eclipse - instance 1 and 2?

when click on run button, emulator (in your case or a real device) runs your application. please don't run it in other AVD (if i get correctly based on your instance 1 and 2). If you have put log code in your onCreate() and onPause() methods, For example Log.i(TAG, "I'm in onCreate()!");, you should see it in logcat. therefore, when you launch your app you will see onCreate message and when you click on home button for example, you will see onPause() message.

This is the way which is guaranteed to be called.

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