prevent活动堆栈进行恢复?堆栈、prevent

2023-09-12 22:11:38 作者:ポ

当一个应用程序的过程中被杀死,其行为堆栈保存。然后,当应用程序重新启动,我的所有活动,并恢复运行到空指针。而不是修改每一项活动,以适应这种情况下,我宁愿只是有我的应用程序从基本活动,而不是尝试重新创建活动的堆栈。

When an application's process is killed, its activity stack is saved. Then when the application is restarted, all my activities resume and run into null pointers. Rather than modify every activity to accommodate this event, I would rather just have my application start with the base activity and not try to re-create the activity stack.

这可能吗?

我知道Intent.FLAG_ACTIVITY_CLEAR_TOP,但据我所知,这将只能杀灭活动已重新创建后。

I know about Intent.FLAG_ACTIVITY_CLEAR_TOP, but as I understand that will only kill activities after they have been re-created.

编辑:是clearTaskOnLaunch我想要的是?我已经把它添加到我的默认行为,但我看到没有效果。但是,这会杀了我的活动,即使我只是最小化应用程序,惯于吗?我宁愿只能清除栈如果整个过程重新启动。

is clearTaskOnLaunch what I want? I've added it to my default activity, but am seeing no effect. But this will kill my activities even if I just minimize the application, wont it? I'd rather only clear the stack if the entire process is rebooting.

编辑2:不,这不是我want-一个Android工程师给予了全面的回应如何使用ClearTaskOnLaunch一些问题:http://groups.google.com/group/android-developers/browse_thread/thread/da024bcaf4e1960f/ab1e2b35c360cb65?pli=1

EDIT 2: No, it's not what I want- an Android engineer gave a thorough response to some questions on how to use ClearTaskOnLaunch: http://groups.google.com/group/android-developers/browse_thread/thread/da024bcaf4e1960f/ab1e2b35c360cb65?pli=1

推荐答案

我能找到是的onCreate(每个实例来检查一个全局静态变量),并完成,如果这个变量已经被重置为null唯一的解决办法,指示任务已经重新启动。我关闭所有活动记在我的根系活力,并重新开始。

The only solution I was able to find was to check a global static variable in every instance of onCreate() and finish if that variable had been reset to null, indicating the task had been restarted. I close all activities down to my root activity and start over.

很快,我希望能有在它可以节省需要值的onPause()点我的应用程序,但是,直到那么这是唯一可靠的方法,我知道有失去的初始化工作...

Soon I hope to have my app at a point where it can save needed values in onPause(), but 'til then this is the only reliable way I know to work with lost initialization...