防止活动堆栈被恢复? [英] Prevent Activity Stack from being Restored?

查看:30
本文介绍了防止活动堆栈被恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个应用程序的进程被杀死时,它的活动堆栈被保存.然后当应用程序重新启动时,我的所有活动都会恢复并遇到空指针.与其修改每个活动以适应此事件,我宁愿让我的应用程序从基本活动开始,而不是尝试重新创建活动堆栈.

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:不,这不是我想要的 - 一位 Android 工程师对有关如何使用 ClearTaskOnLaunch 的一些问题给出了详尽的答复:http://groups.google.com/group/android-developers/browse_thread/thread/da024bcaf4e1960f/ab15?ppli=1" rel="noreferrer">

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...

这篇关于防止活动堆栈被恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆