views:

170

answers:

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 ?

A: 

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
my app has many activities and the user can press home key from any of the activities to reach the home screen.
frieza
A: 

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
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
frieza
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
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 ?
frieza