Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:alwaysRetainTaskState = false not being respected, task state always retained

I would like my app to exhibit the default behaviour described for android:alwaysRetainTaskState in the Android documentation:

Normally, the system clears a task (removes all activities from the stack above the root activity) in certain situations when the user re-selects that task from the home screen. Typically, this is done if the user hasn't visited the task for a certain amount of time, such as 30 minutes.

This isn't what I'm seeing. Even after >1 day, re-starting my app using the launcher icon returns the user to the place where they left it. For example, after a fresh install my app displays a home screen activity H when launched. The user then navigates to detail activities: H -> J. On relaunching after a long time, I would like the user to see H, but instead they see J.

These are the flags set on my activity in the AndroidManifest.xml:

<activity
    android:name=".AppHomeScreen"
    android:label="@string/app_name"
    android:alwaysRetainTaskState="false"
    android:launchMode="singleTop"
    android:windowSoftInputMode="stateUnchanged">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

I am running Android KitKat 4.4.2.

Is there any reason why I might not be seeing the expected behaviour here? I know that I could set android:clearTaskOnLaunch or android:finishOnTaskLaunch to clear the task every time the user leaves the app, but this is too aggressive, I'd like the described behaviour where the state is only forgotten after a long period of inactivity.

(The Android documentation doesn't seem to guarantee the behaviour, only that the task is cleared in "certain situations" and "after a certain amount of time, such 30 minutes". Maybe the default behaviour was changed and the Android docs are out of date?)

like image 326
alzy Avatar asked Oct 18 '25 03:10

alzy


1 Answers

This behaviour is manufacturer/vendor-specific. On different devices you will see different behaviour. There are devices that aggressively clear out tasks and others that retain task state for much longer periods of time.

like image 64
David Wasser Avatar answered Oct 19 '25 20:10

David Wasser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!