Activity not visible in Recents when app is in background
Asked Answered
O

2

6

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?

Octavie answered 26/6, 2014 at 17:37 Comment(8)
have you tried it in multiple devices? Be sure first before banging your head.Pikeperch
Good point, yet yes, I tried to repro on many devices and emulators and it happens all the time. It occurs on 2.x and on 4.x. I haven't tried if my "fix" solves this issue for 2.x, but it does for 4.xOctavie
I am preety sure your blunder is android:launchMode="singleTask" along with exculdeFromRecents a singletask will never leave a backstack and excludefromrecents prevents the one that could be on backstack from being there not so surePikeperch
But I kept android:launchMode="singleTask" - only removed excludeFromRecents from StartActivity and all works. That's why I am in WTF mode now.Octavie
What's the entry point for AccountsActivity? From what I can see, that's StartActivity -> AccountsActivity. No?Bemba
@shoerat: why does it matter?Octavie
I am not sure, but android:excludeFromRecents="true" of the parent activity can be causing that behaviour. Can you post the intent you are using to launch AccountsActivity?Bemba
@shoerat: no flags. Just ordinary startActivity()Octavie
M
9

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".

Metrist answered 8/7, 2014 at 9:36 Comment(2)
"That is, when this activity is the root activity of a new task"Frederiksberg
The word "task" is what I managed to not spot in right context. Thanks for pointing that out.Octavie
K
-1

Just Remove

android:excludeFromRecents="true"

or set to false will solve your problem.

Kantar answered 7/4, 2023 at 11:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.