当应用程序在后台时,活动在“最近"中不可见 [英] Activity not visible in Recents when app is in background

查看:47
本文介绍了当应用程序在后台时,活动在“最近"中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题描述

在我的一个应用程序中,我看到了很奇怪的行为:当我的应用程序在前台运行时(最上面的一个),我可以在系统的最近"中看到它的活动.但是,一旦我将其置于后台,不久前列出的相同活动(即 AccountsActivity)就不再出现在最近"中.我的清单文件的相关部分:

<应用程序android:name=".WebnetApplication"机器人:allowBackup =假"android:allowClearUserData="true"安卓:硬件加速=真"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><活动android:name=".StartActivity"android:alwaysRetainTaskState="true"android:excludeFromRecents="true"android:label="@string/app_name"android:theme="@android:style/Theme.NoDisplay" ><意图过滤器><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></意图过滤器></活动><活动android:name=".AccountsActivity"机器人:excludeFromRecents =假"android:launchMode="singleTask"android:windowSoftInputMode="adjustResize"/>...

调查结果

因为这是我唯一一个行为不端的应用程序,我检查了所有样式,以及我的 WebnetActivityWebnetApplication 以确保我不会调用任何可能影响最近.没有这样的事情.

然后我开始剥离 Manifest 文件,看看是否会发生一些变化.正如预期的那样,罪魁祸首潜伏在那里,我仍然不清楚为什么.开始时,Manifest 中的 AccountsActivity 条目根本没有 android:excludeFromRecents 条目 - 这导致 AccountsActivity 在最近"中根本不可见.当我添加 android:excludeFromRecents="true" 时,活动在最近"中可见,但仅当它在前面时.当我移到后面时,它从最近"中消失了.当我从 StartActivity 声明中删除 android:excludeFromRecents="true" 时,AccountsActivity 在最近"中变得可见,无论应用程序是在前面还是在后台,并且我也可以完全从其条目中删除 android:excludeFromRecents ,也没有任何问题.

问题

目前我正在低头试图理解为什么它会这样表现 - 这是正常的(我不知道某些东西)还是可能是框架中的错误?任何人都遇到过类似的问题,可以分享经验、想法或解释吗?

解决方案

从主要活动中删除 android:excludeFromRecents="true".

引自 android:excludeFromRecents:><块引用>

是否应排除此活动发起的任务从最近使用的应用程序列表(最近的应用程序").那是,当此活动是新任务的根活动时,此属性确定任务是否不应出现在最近的列表中应用.如果任务应该从列表中排除,则设置true";放如果应包括在内,则为false".默认值为false".

Issue description

In one of my apps I am seeing quite odd behaviour: when my app is running in foreground (is top-most one), then I can see its activities in system's Recents. But as soon as I put it into background, the same activity (i.e. AccountsActivity) that was listed moments ago is no longer present in Recents. Related portion of my Manifest file:

<application
    android:name=".WebnetApplication"
    android:allowBackup="false"
    android:allowClearUserData="true"
    android:hardwareAccelerated="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".StartActivity"
        android:alwaysRetainTaskState="true"
        android:excludeFromRecents="true"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoDisplay" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".AccountsActivity"
        android:excludeFromRecents="false"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize" />

    ...

Findings

Since this is the only app of mine that misbehaves that way, I checked all styles, and my WebnetActivity and WebnetApplication to ensure I do not call anything that could influence Recents. There's nothing like this.

Then I started to strip down Manifest file to see if something would change. And as expected, the culprit lurks there, still it's no really clear for me why. At start, AccountsActivity entry in Manifest had no android:excludeFromRecents entry at all - this resulted in AccountsActivity being not visible in Recents at all. When I added android:excludeFromRecents="true" then the activity becomes visible in Recents, but only when it was in front. When I moved to back, then it disappeared from Recents. When I remove android:excludeFromRecents="true" from StartActivity declaration, then AccountsActivity become visible in Recents regardless app is in front or in background and I can remove android:excludeFromRecents from its entry completely without any problems as well.

Question

At the moment I am bending my head trying to understand why it all behaves that way - is it normal (and I do not know something) or it is perhaps rather bug in framework? Anyone faced similar issue and can share experience, ideas or explanation?

解决方案

Remove android:excludeFromRecents="true" from main activity.

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

这篇关于当应用程序在后台时,活动在“最近"中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆