[英]delete activity from recent, when the application is running
I would turn the flags noHistory and excludeFromRecents , when the activity is already running. 当活动已经在运行时,我将标记noHistory和excludeFromRecents 。 For example, when google chrome opens in incognito mode notification is generated, that when you click on it eliminates all activities of the stack and removed from recent. 例如,当谷歌浏览器以隐身模式打开时,将生成通知,当您单击它时,将消除堆栈中的所有活动并从最近的活动中删除。 I want to do something like this, with some activities of my app. 我想通过我的应用程序的一些活动来执行类似的操作。
Edit: The solution proposal by David Wasser works, but my problem is a bit more complicated. 编辑: David Wasser的解决方案可行,但我的问题要复杂一些。 This is my manifest.xml 这是我的manifest.xml
...
<activity
android:name=".ActivityRecive"
android:excludeFromRecents="true"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
</activity>
<activity
android:name=".ActivityPasswordToIncognito">
</activity>
<activity
android:name=".ActivityIncognitoMode1">
</activity>
<activity
android:name=".ActivityIncognitoMode2">
</activity>
<activity
android:name=".ActivityIncognitoMode3"
</activity>
...
ActivityRecive: begins as a result of intent. ActivityRecive:由于意图而开始。 I want this activity is excluded from the stack and exclude From recent. 我希望将此活动从堆栈中排除,并从最近开始排除。 ActivityRecive can launch ActivityPasswordToIncognito. ActivityRecive可以启动ActivityPasswordToIncognito。
ActivityPasswordToIncognito: "normal" activity. ActivityPasswordToIncognito:“正常”活动。 ActivityPasswordToIncognito can launch ActivityIncognitoMode(X). ActivityPasswordToIncognito可以启动ActivityIncognitoMode(X)。
ActivityIncognitoMode(X): they can launch ActivityIncognitoMode(x+1) and I want that when the user exit from incognito mode are deleted from recent and stack. ActivityIncognitoMode(X):他们可以启动ActivityIncognitoMode(x + 1),我希望当用户从隐身模式退出时,从最近的用户和堆栈中删除它们。
The problem is that the root Activity(ActivityRecive) used android: excludeFromRecents="true", then the all activity in task is excluded from recent. 问题是,根Activity(ActivityRecive)使用的是android:excludeFromRecents =“ true”,则任务中的所有活动都被排除在最近。 I have tried using FLAG_ACTIVITY_NEW_TASK to launch ActivityPasswordToIncognito, but not work. 我尝试使用FLAG_ACTIVITY_NEW_TASK启动ActivityPasswordToIncognito,但无法正常工作。
If you want to make your entire application go away, and leave no trace in the "recent tasks" list, you should be able to do something like this: 如果要使整个应用程序消失,并且在“最近的任务”列表中不留任何痕迹,则应该可以执行以下操作:
Intent intent = new Intent(this, MyRootActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.putExtra("finish", true);
startActivity(intent);
In your root activity, add the following code to onCreate()
: 在您的根活动中,将以下代码添加到onCreate()
:
super.onCreate();
if (getIntent().hasExtra("finish")) {
// Need to finish now
finish();
return;
}
... rest of your onCreate() code...
This will clear the stack back to your root activity (the one with ACTION=MAIN and CATEGORY=LAUNCHER) and then the root activity will exit. 这会将堆栈清除回您的根活动(具有ACTION = MAIN和CATEGORY = LAUNCHER的堆栈),然后退出根活动。 Because the root activity is launched with Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
it shouldn't show up in the list of recent tasks. 因为根活动是使用Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
启动的, Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
它不应显示在近期任务列表中。
NOTE: This will only work if your root activity stays in the activity stack when it launches other activities in your application (ie: doesn't call finish()
). 注意:仅当您的根活动在应用程序中启动其他活动时仍保留在活动堆栈中(即:不调用finish()
)时,此方法才有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.