3

I would like the distinguish the event where a user resumes my app from the "recent apps" list, or from the launcher icon again even if there is an unfinished app running in the background.

My app is a single Activity containing multiple Fragments, the intended behavior is that if the user resumes from "recent apps", I wouldn't have to do anything as the default behavior brings them back to the fragment they left it at. However, when the user launches the app from the icon again, I want to pop all the fragments in my fragment manager to the first fragment, essentially behaving as if starting the app fresh.

Right now though, even if the user taps on the launcher icon, the app will be resumed as usual like from the "recent apps" list without onCreate() being called on the Activity. I've looked at similar questions, but they seem to indicate that the activity DOES get recreated when the user launches from the icon again, which is weird and not what I observe: Android resume app from recent applications list

Any ideas?

Community
  • 1
  • 1
Jason Hu
  • 1,237
  • 2
  • 15
  • 29
  • 1
    I don't think there is any way to do this, sorry. – Alex K Jan 02 '15 at 20:53
  • 1
    This is standard Android behaviour. There is no difference between "launching an app via icon from the HOME screen" and "launching an app by selecting it from the list of recent tasks". These 2 actions are exactly the same and you cannot tell the difference. The accepted answer to the question that you linked to in your post is, unfortunately, wrong :-( – David Wasser Jan 05 '15 at 14:30

1 Answers1

0

You can try adding this attribute to your manifest file for your activity.

<activity>
   ...
   android:launchMode="singleTask"
</activity
Ana Ilies
  • 41
  • 2