Search code examples
androidadbandroid-lifecycle

application launch behavior is not always the same


I am currently facing an issue I do not understand on Android.

For example I have installed the exoplayer demo android app and I follow the following instructions :

  • launch the app clicking on the icon
  • navigate through the app
  • put the app in background
  • relaunch the app clicking on the icon

Expecting behavior : the system resumes my app

Current behavior : the system resumes my app (great!)

You can see the result here : https://youtu.be/BGyr_BpJQUY

Now I simulate the fact that a user opens the app from the Google Play Store (for example) clicking on the "open" button so I execute the following instructions :

  • in a terminal : adb shell
  • launch the app with the command line : am start -n com.google.android.exoplayer2.demo/.SampleChooserActivity
  • navigate through the app
  • put the app in background
  • relaunch the app clicking on the icon

Expecting behavior : the system resumes my app

Current behavior : the system restarts my app (bad!)

You can see the result here : https://youtu.be/nNnYQUrrU4o

In this second case, I do not go in the onDestroy life event (in my activity or my fragment) so it breaks workflow in it...

Is there a way to handle this case ? Someone is able to explain me this issue ?

Thank you for your help !


Solution

  • @ABS gives the correct answer in comments:

    Check if this works and is same as google play intent: adb shell am start -n "app.package.name/activity.package.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER