FromNotificationActivity

FromNotificationActivity

本文介绍了为什么excludeFromRecents删除所有活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有两个入口点(MainActivity和FromNotificationActivity)。

My app has two entry points (MainActivity and FromNotificationActivity).

我想MainActivity出现在最近的任务,但不FromNotificationActivity)

I want MainActivity to appear in recent tasks, but not FromNotificationActivity)

通过没有在清单中声明,如果我做...

With nothing declared in the manifest, if I do...

  • MainActivity
  • 返回
  • FromNotificationActivity
  • 返回

...我发现FromNotificationActivity在最近的任务中列示

... I find FromNotificationActivity listed in recent tasks

如果我加入安卓excludeFromRecents =真正的来FromNotificationActivity在清单中,并重复同样的顺序,我觉得什么最近名单。

If I add android:excludeFromRecents="true" to FromNotificationActivity in the manifest and repeat the same sequence, I find nothing in the recent lists.

什么咒语,我必须调用,这样的步骤上面的序列之后,我在最近的名单得到MainActivity。

What incantations must I invoke such that after the above sequence of steps, I get MainActivity in the recent list.

推荐答案

在默认情况下,一个应用程序的所有活动,具有相同的亲和力。具有相同的亲和性活动概念属于相同的任务。因此,在这种情况下,两个 MainActivity FromNotificationActivity 属于相同的任务。 安卓excludeFromRecents 确保任务没有在最近的应用程序上市。这是原因,当安卓excludeFromRecents 设置为 FromNotificationActivity MainActivity 历史disappers。

By default, all the activities of an application have the same affinity. Activities with same affinity conceptually belong to the same task. Hence in this case both MainActivity and FromNotificationActivity belong to the same task. android:excludeFromRecents ensures the task is not listed in the recent apps. That is the reason, when android:excludeFromRecents is set to true for FromNotificationActivity, MainActivity disappers from history.

解决方法:使用安卓taskAffinity 来指定两个活动不同的任务。使用机器人:excludeFromRecents FromNotificationActivity ,如果该任务不应该在历史上被显示在所有

Solution: Use android:taskAffinity to specify different tasks for both the activities. Use android:excludeFromRecents for FromNotificationActivity if that task should not be shown in history at all.

<activity   
    android:name="com.example.MainActivity"
    android:label="@string/app_name"
    android:taskAffinity=".MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity> 

<activity android:name="com.example.FromNotificationActivity"
    android:label="@string/notification_name"
    android:taskAffinity=".NotificationActivity"
    android:excludeFromRecents="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity> 

这篇关于为什么excludeFromRecents删除所有活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 10:03