Search code examples
androidandroid-homebuttonandroid-recents

Flow change on Home button press when opening app from APP Tray or from Recent app in Android?


Why Android apps act differently when opening app from application icon and opening from Recent apps (after exiting application by pressing Home button)?

Example : Start Activity A -> Activity B then press home button.

  1. Opening application from app icon will take you back to Activity A.

  2. Opening application from recent apps will take you to Activity B.


Solution

  • Setting attribute "android:alwaysRetainTaskState" to "true" will solve this problem as this will retain the state of the activity as it is. It doesn't allow system to reset activity state.

    "android:alwaysRetainTaskState

    Whether or not the state of the task that the activity is in will always be maintained by the system — "true" if it will be, and "false" if the system is allowed to reset the task to its initial state in certain situations. The default value is "false". This attribute is meaningful only for the root activity of a task; it's ignored for all other activities."