I am trying to fix a bug in my code, and am hoping someone can point me in the right direction. If my app goes into the background, and gets resumed by the user just going into "apps" and selecting my app, everything works fine.
However, if they put it into the background and resume it by holding down the home button, and selecting it from the recent apps list, I get a bug. I was under the impression these two actions should do the exact same thing?
Does anyone know what the difference is between resuming an app from the normal list of apps, vs resuming it by holding the home button down and then selecting the it from that list?
The exact answer depends a bit on the implementation of your Home Screen or Launcher App. However, from what I experienced so far I'm pretty sure that ...
... apps, that are started from your menu or home screen are usually started by an Intent
. To be more precise: the active launcher shows all activities in its menu that have an action android.intent.action.MAIN"
and category android.intent.category.LAUNCHER
and if you select an app, it creates an Intent
and by this start the app:
Intent intent = new Intent(Launcher.context, SelectedActivity.class);
intent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
This creates most likely a new instance of your started app activity, apart from some flags that might avoid this (android:launchMode="singleTop"
)
... looking at recent tasks this works differently as far as I could see: the task list relies most likely on a list that is created by getRecentTasks() and brings the selected app to front. This can be done by using moveTaskToFront(). Only if the app/activity has been finished it is newly created (try killing the app, and you'll see it is recreated).
Conclusion: as you can see the recent task list works rather like a (go) back to the app causing potentially an onResume()
whereas starting the app from the menu will cause an onCreate()
.
Note: one application package might contain more that one app. The Contacts and Phone app are in many cases just two different activities in one supplied application package (i.e. APK file).
Hope this helps to understand the different behavior ... Cheers!