android - 如何清理 Android API 10 (Android 2.3.3) 上的返回堆栈

标签 android android-intent android-activity android-compatibility

我想知道如何清除堆栈中所有以前的 Activity (新 Activity 除外),但我想在 Android API 10 (Android 2.3.3) 中进行清理。

以此为指导answer ,我知道这不是直接可能的,因为自 API 11 以来就存在专门用于执行此操作的标志。

但我想知道这是否可能具有某种兼容性,或者是否有人有任何解决方案。

提前致谢。

最佳答案

执行此操作的方法是始终使用 startActivityForResult() 开始您的 Activity 。如果您想要清理 Activity 堆栈,请调用当前 Activity setResult(RESULT_CANCELED),然后调用 finish()。在所有 Activity 中(除了您的主要 Activity 或“根” Activity )都有以下方法:

@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_CANCELED) {
        // Want to clear the activity stack so I should just go away now
        setResult(RESULT_CANCELED); // Propagate result to the previous activity
        finish();
}

这将完成堆栈中的所有 Activity 。

关于android - 如何清理 Android API 10 (Android 2.3.3) 上的返回堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12234430/

相关文章:

android - 如何像在 Google Keep 中那样添加复选框 ListView?

android - 如何在我的 Android 应用程序中使 View 填充其父级的整个宽度?

Android(App)Widget识别

javascript - Phonegap Android 使用 JavaScript 读取 SD 卡上的文件

android - 将 pdf 附加到电子邮件,授予权限

android - 无法启动快捷方式 : Application is not installed on your phone

android - 如何区分onDestroy是否会在onPause之后被调用

android - onActivityResult 没有从 Intent 中获取字符串

java - 如何使 "menu"或 "manifest"后退按钮导航回上一个 Activity

java - 使用多个 Intent 时如何避免跳过 Activity ?