开发者

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

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 ?


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


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.


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.


If an app comes from the background, you can check it by getting intent flags

intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0

it will be true if your app comes from the background. If you click on the app icon to open it, the above logic will not be true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜