2

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 ?

pankajagarwal
  • 13,462
  • 14
  • 54
  • 65

4 Answers4

4

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

pankajagarwal
  • 13,462
  • 14
  • 54
  • 65
0

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.

Karan
  • 12,724
  • 6
  • 40
  • 33
0

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.

Vamsi
  • 5,853
  • 6
  • 29
  • 36
  • you are right that I will get a callback onResume() for the last open activity, but this callback is also received when i comeback to an activity from another activity. Say what if I want to show a splash-screen every time a user clicks the app icon – pankajagarwal May 07 '10 at 08:27
  • so what you are asking is you want to exit the application when it loses the user attention? if that is the case, you can call ::finish():: when the top activity loses its user-attention[UA] (at the time when activity loses its UA ::onPause():: will be called)and have to do the same with other activities. In the you dont want to exit the application, you have to show the requires splashy screen during ::onResume():: – Vamsi May 07 '10 at 13:06
  • I agree with what you say. But what I wanted to know was that, is there any way to know if my app is in foreground or background as you can determine in a BlackBerry device ? – pankajagarwal May 10 '10 at 04:24
0

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.

m4n0
  • 29,823
  • 27
  • 76
  • 89