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
2010-05-07 04:19:57
my app has many activities and the user can press home key from any of the activities to reach the home screen.
frieza
2010-05-07 04:42:24
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
2010-05-07 06:14:27
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
2010-05-07 08:27:54
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
2010-05-07 13:06:42
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
2010-05-10 04:24:22