问题
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