[英]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 . 我选择将
OnPause()
方法中的持久应用程序状态保存到我的数据库中,因为根据活动生命周期的文档,保证在应用程序被杀死之前调用OnPause()
。
Now I am facing following behaviour using eclipse and avd emulator (api level 8): 现在我使用eclipse和avd模拟器(api level 8)面临以下行为:
1. I start my application via eclipse - Instance1 1.我通过eclipse启动我的应用程序 - Instance1
2. I start my application via eclipse again - Instance2 2.我再次通过eclipse启动我的应用程序 - Instance2
Now Instance1 is being terminated without calling OnPause()
! 现在Instance1正在终止而不调用
OnPause()
!
Could somebody please explain me why OnPause()
is not being called? 有人可以解释一下为什么没有调用
OnPause()
吗? 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.
如果不是这种情况,也许是因为eclipse终止Instance1进程的方式,那么我想知道我是否可以改变它。 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. 当您通过eclipse启动应用程序时,它将有效地从已经在设备或模拟器上运行的同一应用程序的任何实例中删除地毯。 This will never happen in practice, only when running from eclipse.
这在实践中永远不会发生,只有在从eclipse运行时才会发生。
So you can plan on onPause() always being called. 因此,您可以计划onPause()始终被调用。
what you mean you start application via eclipse - instance 1 and 2? 你的意思是你通过eclipse启动应用程序 - 实例1和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).
请不要在其他AVD中运行它(如果我根据你的实例1和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.
如果你已经在onCreate()和onPause()方法中添加了日志代码,例如Log.i(TAG,“我在onCreate()!”);,你应该在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.
因此,当您启动应用程序时,您将看到onCreate消息,当您单击主页按钮时,您将看到onPause()消息。
This is the way which is guaranteed to be called. 这是保证被调用的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.