[英]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. 您将不得不考虑并尝试使用用户在堆栈中移动时会发生什么,以及是否会使您的应用重新出现在最近的应用中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.