android - 清除android中的所有 Activity

标签 android android-activity

我有 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/

相关文章:

android - 是否有与 Widget.Material.Spinner.Underlined 等效的 AppCompat?

java - 安卓最终变量

android - Parcelable with arraylist<CustomClass> 将值从 Activity 传递到 fragment android

android - 在 Android 中为电子书类型应用程序使用 Activity 与 View

android - 如何更改primary和primaryDark颜色?

Android:添加单页标题条栏

android - onBindDialogView 未调用 - 为什么?

android - 如何关闭 BluetoothSocket 在 Android 中的屏幕旋转?

android - PendingIntent 中的 TaskStackBuilder 不工作

android - 如何从调用的电话代码(例如#120)开始一个 Activity