简体   繁体   English

在模拟器中重新启动活动时未调用OnPause()

[英]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.

相关问题 在片段之间切换时会调用Activity onpause吗 - Will Activity onpause be called when switching between fragments Android 活动生命周期 - 何时调用“onPause”? - Android Activity LifeCycle - when 'onPause' is called? onPause 是否保证在 Activity 不再运行时调用? - Is onPause guaranteed to be called when an Activity is no longer running? 在Activity上调用onPause时,数据会发生什么 - What happens to data when onPause is called on Activity 当打开dialogFragment并调用onPause()时,活动崩溃 - Activity crashes when dialogFragment is opened and onPause() is called 当其他活动打开时,从未调用过OnPause()和onDestroy() - OnPause() and also onDestroy() never called when other activity opened 没有调用onPause的整理活动 - Finishing activity without onPause called 第一个活动的onPause在连续启动两个活动时未调用,而第二个活动具有半透明主题 - first activity's onPause not called when start two activity continuously and the second activity with translucent theme onPause()在我的活动中被调用。 然后,当回到顶部时,onResume()永远不会被调用 - onPause() gets called on my activity. Then, when brought back to the top, onResume() never gets called 启动活动后立即调用OnPause和OnStop() - OnPause and OnStop() called immediately after starting activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM