简体   繁体   English

当应用程序正在运行时,从最近删除活动

[英]delete activity from recent, when the application is running

I would turn the flags noHistory and excludeFromRecents , when the activity is already running. 当活动已经在运行时,我将标记noHistoryexcludeFromRecents 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.

相关问题 从最近的任务启动应用程序时启动了错误的活动 - Wrong Activity launched, when launching application from recent task 当子活动从android中的最近列表开始时如何重新启动应用程序 - How to restart the application when a sub activity start from recent list in android 当我的应用程序在“最近使用的应用程序”列表中时,如何启动特定活动? - How to Launch specific activity when my Application is in Recent Apps List? 关闭活动时从“最近使用的应用程序”中删除应用程序 - Remove application from Recent app while closing the activity 从NFC启动的活动/应用程序永远不会出现在最近的应用程序列表中 - Activity/Application Launched From NFC Never Appears in Recent Apps List 在Activity上调用finish()时从最近的应用程序列表中排除该应用程序 - Excluding the application from recent app list on invoking finish() on Activity 从不同的活动 Android 中删除正在运行的服务 - Delete a running Service from a different activity Android 从窗口小部件启动时,活动未显示在最近的应用列表中 - Activity not showing in list of recent apps when launched from a widget 当应用程序从 android 的最近列表中删除时,会调用哪个活动? - Which activity is called when app removed from recent list in android? 从“最近的应用程序”启动时,PopUp Activity再次启动 - PopUp Activity starts again when it is started from “recent apps”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM