首页 > 解决方案 > 清除堆栈而不调用 startActivity()

问题描述

我正在进行某个活动,如果某个条件为真,我想清除所有先前的堆栈。

if (condition_is_true) {
// Clear stack
}

我不能使用:

  1. 因为,我想先检查条件

    <activity
        android:name=".CurrentActivity"
        android:noHistory="true" />
    
  2. 因为,我不想开始新的活动

    Intent nextIntent = new Intent(CurrentActivity.this,
                                   NextActivity.class);
    nextIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                      | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(nextIntent);
    

标签: androidandroid-intent

解决方案


推荐阅读