我想在我的HomeScreenActivity中命中一个意图,并清除堆栈中所有活跃的活动,下面是意图代码:
Intent intent = new Intent(activity, HomeScreenActivity.class);
if (Build.VERSION.SDK_INT >= 11) {
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
finish();
堆栈没有被清除,当我按下返回键时,所有先前的活动都显示出来,这不是预期的结果。
请帮忙!
同时使用两个标志:
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
第一个标志在当前任务(活动堆栈)中不可用时创建新活动或重用现有活动。第二个标志清除与请求的活动相关联的任务。
use
Intent.FLAG_ACTIVITY_NO_HISTORY