简体   繁体   English

如何在完成时从最近的应用列表中删除活动?

[英]How to remove activity from recent apps list on finish?

I'm launching an activity from a service and want it to appear in the recent apps list. 我正在从服务启动活动,并希望它出现在最近的应用列表中。

However, I want the activity to be removed from the recent apps list if I exit the application (eg press button on activity's UI which calls finish()). 但是,如果我退出应用程序,我希望从最近的应用程序列表中删除活动(例如,按活动的UI上的按钮调用finish())。

Excluding the activity from the recent apps list with android:excludeFromRecents="true" does not give me the initial activity behaviour that I require, ie the activity appearing in the recent apps list. 使用android:excludeFromRecents="true"从最近的应用列表中排除活动并不能提供我所需的初始活动行为,即最近的应用列表中显示的活动。

Is this possible? 这可能吗?

Use 使用

android:excludeFromRecents="true"

for the activity in manifest file 清单文件中的活动

android:excludeFromRecents

Whether or not the task initiated by this activity should be excluded from the list of recently used applications ("recent apps"). 是否应从最近使用的应用程序列表(“最近的应用程序”)中排除此活动启动的任务。 That is, when this activity is the root activity of a new task, this attribute determines whether the task should not appear in the list of recent apps. 也就是说,当此活动是新任务的根活动时,此属性确定该任务是否不应出现在最近的应用列表中。 Set "true" if the task should be excluded from the list; 如果任务应从列表中排除,则设置为“true”; set "false" if it should be included. 如果应该包含它,则设置“false”。 The default value is "false". 默认值为“false”。

对于api> 21你可以尝试finishAndRemoveTask()而不是finish()

Yes, generally when you want to have special properties for an Activity when starting it you supply special flags to the Intent. 是的,通常当您想要在启动时为Activity提供特殊属性时,您需要为Intent提供特殊标志。 In this case FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS . 在这种情况下, FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

Updated: 更新:

If you need to hide the current already running activity, you might be able to use this flag in combination with FLAG_ACTIVITY_CLEAR_TOP which would send the new Intent to the existing Activity. 如果您需要隐藏当前已在运行的活动,您可以将此标志与FLAG_ACTIVITY_CLEAR_TOP结合使用,这将把新Intent发送到现有的Activity。 You'll have to think and perhaps experiment with what happens as the user moves around your stack though and whether that will make your app re-appear in the recent apps. 您将不得不考虑并尝试使用用户在堆栈中移动时会发生什么,以及是否会使您的应用重新出现在最近的应用中。

source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 活动会从最近的应用列表中删除该应用 - An Activity removes the app from recent apps list 从最近的应用列表中排除活动 - Exclude activity from recent apps list 在Activity上调用finish()时从最近的应用程序列表中排除该应用程序 - Excluding the application from recent app list on invoking finish() on Activity 从窗口小部件启动时,活动未显示在最近的应用列表中 - Activity not showing in list of recent apps when launched from a widget 从NFC启动的活动/应用程序永远不会出现在最近的应用程序列表中 - Activity/Application Launched From NFC Never Appears in Recent Apps List Android-从操作系统的应用程序“最近使用的应用程序”列表中启动的活动 - Android - Activity launched from the OS's app recent apps list 如何仅显示最近使用的应用列表中的主要活动? - How to show only the main activity in the recent apps list? 当我的应用程序在“最近使用的应用程序”列表中时,如何启动特定活动? - How to Launch specific activity when my Application is in Recent Apps List? 终止应用程序并从最近的应用程序列表中删除[Android] - Kill application and remove from recent apps list [Android] 按返回键无法完成我的应用。 但是将其从最近的应用列表中删除可以 - Press back key can't finish my app. But removing it from recent apps list can
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM