我有 4 个 Activity 1.Home、2.B、3.C 和 4.D。每当我从 Activity D 开始回家时,我都想完成所有其他 Activity 。我使用了这段代码,但是当我从主页按下后退按钮时,它会将我带到上一个 Activity 。我在这里做错了什么。?
Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent)
最佳答案
你可以试试这个,
Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
注意:如 FLAG_ACTIVITY_CLEAR_TOP 中所述文档
This launch mode can also be used to good effect in conjunction with FLAG_ACTIVITY_NEW_TASK: if used to start the root activity of a task, it will bring any currently running instance of that task to the foreground, and then clear it to its root state. This is especially useful, for example, when launching an activity from the notification manager.
关于android - 清除android中的所有 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20113060/