2

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.

guipivoto
  • 18,327
  • 9
  • 60
  • 75
Sumit T
  • 1,273
  • 2
  • 17
  • 32
  • Interesting question.. I never noticed that. I have an app and all the fragments from Activity A remains the same... However, Activity B is discarded... – guipivoto Feb 24 '16 at 19:10
  • You android manifest has android:launchMode="singleTask"? – guipivoto Feb 24 '16 at 19:36
  • For which activity do you want me to make it singleTask - Activity A or B or both? – Sumit T Feb 24 '16 at 19:44
  • No no.. just asking if you have it in any of your activities? I could reproduce the issue only after adding that... without singleTask, issue was not happening and Activity was started in the same way for both methods – guipivoto Feb 24 '16 at 19:45
  • @Guilherme P : You are right, one of my activity was singleTask which was starting another activity. Removing it will work. Thanks. But what if we want to make it singleTask because I don't want to create multiple instances for this activity. – Sumit T Feb 24 '16 at 20:03
  • We have to search more... If I figure out how, I'll share with you. – guipivoto Feb 24 '16 at 21:17
  • Thanks for help @GuilhermeP – Sumit T Feb 24 '16 at 21:50

1 Answers1

0

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

Sumit T
  • 1,273
  • 2
  • 17
  • 32