Determine when application icon is clicked to launch the app in android

筅森魡賤 提交于 2021-02-08 03:36:26

问题


Is there any way in android to determine when the user clicked the app icon to launch the app ? I mean say a user was using my app. Then he presses the home key as a result of which the app goes to the background. After sometime he clicks the app icon again. My question is do I get a call-back for this ?


回答1:


Just to inform, I used the flag android:clearTaskOnLaunch="true" in my launcher activity. As a result, its onResume method was called and I could identify that the launcher icon was clicked




回答2:


It will call the onResume() method if the app is already in the stack. And if the app not in the stack then it will call the onCreate() method.

This mechanism is based on the launchMode specified for the activity.




回答3:


please read http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

How many activities your application has, you will get a callback onResume() for the last open activity.



来源:https://stackoverflow.com/questions/2786160/determine-when-application-icon-is-clicked-to-launch-the-app-in-android

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