从android中的任务管理器堆栈中删除活动

时间:2020-12-20 20:50:11

I am working on and Android application. When my application is running and i press the recent applications button on the phone , Activity's onPause() method is called . Inside this onPause i call finish() . So the activity gets destroyed.

我正在开发Android应用程序。当我的应用程序运行时,我按下手机上最近的应用程序按钮,调用Activity的onPause()方法。在这个onPause中,我调用finish()。活动被破坏了。

But its still visible in the recent applications list.

但它在最近的应用列表中仍然可见。

How do i make sure it is not listed in the recent applications list when i destroy my activity from onPause().

当我从onPause()销毁活动时,如何确保它不在最近的应用程序列表中列出。

2 个解决方案

#1


5  

Try doing

试着做

<activity android:name=".MainActivity"
        android:excludeFromRecents="true" ...>

in your AndroidManifest.xml's activity declaration.

在你的AndroidManifest。xml的活动声明。

get more from official documentation

从官方文件中获得更多信息

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; set "false" if it should be included. The default value is "false".

该活动发起的任务是否应该被排除在最近使用的应用程序列表之外(“最近的应用程序”)。也就是说,当该活动是新任务的根活动时,该属性确定该任务是否不应该出现在最近的应用程序列表中。如果任务应该从列表中排除,则设置为“true”;如果应该包含“false”,则设置为“false”。默认值是“false”。

when you want to have special properties for an Activity when starting it you supply special flags to the Intent. In this case FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS.

当您希望在启动活动时为活动提供特殊属性时,您将为意图提供特殊标志。在这种情况下FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS。

Go through link.

通过链接。

#2


0  

The reason may be because only your activity is destroyed not the Application instance. Android awaits may be user open up the app again. To completely terminate application you can use for above API 16 this.finishAffinity() .

原因可能是因为只有您的活动被破坏,而不是应用程序实例。Android等待可能是用户再次打开应用程序。要完全终止应用程序,可以使用上面的API 16 this.finishAffinity()。

It will finish the current activity and all other under it. As doc says

它将完成当前活动和它下面的所有其他活动。就像医生说的

Finish this activity as well as all activities immediately below it in the current task that have the same affinity

完成此活动以及当前任务中紧随其后的具有相同亲和力的所有活动

#1


5  

Try doing

试着做

<activity android:name=".MainActivity"
        android:excludeFromRecents="true" ...>

in your AndroidManifest.xml's activity declaration.

在你的AndroidManifest。xml的活动声明。

get more from official documentation

从官方文件中获得更多信息

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; set "false" if it should be included. The default value is "false".

该活动发起的任务是否应该被排除在最近使用的应用程序列表之外(“最近的应用程序”)。也就是说,当该活动是新任务的根活动时,该属性确定该任务是否不应该出现在最近的应用程序列表中。如果任务应该从列表中排除,则设置为“true”;如果应该包含“false”,则设置为“false”。默认值是“false”。

when you want to have special properties for an Activity when starting it you supply special flags to the Intent. In this case FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS.

当您希望在启动活动时为活动提供特殊属性时,您将为意图提供特殊标志。在这种情况下FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS。

Go through link.

通过链接。

#2


0  

The reason may be because only your activity is destroyed not the Application instance. Android awaits may be user open up the app again. To completely terminate application you can use for above API 16 this.finishAffinity() .

原因可能是因为只有您的活动被破坏,而不是应用程序实例。Android等待可能是用户再次打开应用程序。要完全终止应用程序,可以使用上面的API 16 this.finishAffinity()。

It will finish the current activity and all other under it. As doc says

它将完成当前活动和它下面的所有其他活动。就像医生说的

Finish this activity as well as all activities immediately below it in the current task that have the same affinity

完成此活动以及当前任务中紧随其后的具有相同亲和力的所有活动