What is the difference between launch app from “recent apps” and tapping app icon

浪尽此生 提交于 2020-05-29 03:54:05

问题


I'm working on large project, so there is some logic for saving application state, and then opening correct activity(fragment) when it comes from background. But anyway, I've found that if user navigates through my app and then minimize it - android opens it from background in different ways in following cases:

  1. User taps on app icon (behavior: user see home activity, doesn't matter where he was, when application was minimized)
  2. User select app from android "recent apps" (behavior: user see exactly what he saw, when the application was minimized)

So, what is the difference between launching application from background by this two ways? I always thought, that it is the same mechanism, but, obviously, I was wrong.

Thanks for any answers


回答1:


You should pay atention on the folowing docs Activity and Tasks. In short words: if user start app from recents you will receive onRestart before onStart (without onCreate it means that your app was just "suspended"). You able to save screen state using onSaveInstanceState(). But in general starting from icon and from recents - different application behaviors and you should provide proper code for this ways.

UPD As described below root cause of unexpected behaviour was additional lunchmode attribute.




回答2:


From what I experience as an Android user, both are same.

The difference we usually see is how we close the app

  1. Press back button until app close / finish()

    On this state no matter how we open the apps it will go to the main screen

  2. Press Home button

    On this state depend on the app. If the app does not handle any Activity the app will same with the first state. But if the app handle something like when onPause() the Activity then finish() the apps, then whatever you open with app icon or recent apps will provide the same result.

Correct me if I am wrong



来源:https://stackoverflow.com/questions/18759047/what-is-the-difference-between-launch-app-from-recent-apps-and-tapping-app-ico

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