Android resume app from recent applications list

折月煮酒 提交于 2019-12-04 20:16:10

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

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

  2. ... 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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!