But there doesn't seem to be a solution valid for all cases, then. onResume() will also be called each time I launch the activity. Or it's shown at the foreground, because something which was in front of it was closed. This is not what I want. onCreate() with LAUNCHER category will be called only when the app is indeed created, but this will not be always the case when user opens the app. And in the last case (Application onCreate) there's also the problem that the application will not necessarily be created when the user launches it.
On Wednesday, August 22, 2012 2:00:51 PM UTC+2, casantos wrote: > > On Wed, Aug 22, 2012 at 8:33 AM, user123 <[email protected] <javascript:>> > wrote: > > I want to detect each time the user opens the app, by tap on home / > desktop > > icon. There seem not to be a straight forward way to do it. Found a few > > workarounds but nothing seems to be really reliable. > > The invoking intent will have action "android.intent.action.MAIN" and > category "android.intent.category.LAUNCHER". > > > Things like, extend application object and use method "onCreate()", but > this > > is not what I need because it's not called always when the user taps on > the > > app's icon (can be just brought from the background), > > In this case onResume() will be called, but not onCreate. > > > and also the > > application may be destroyed and recreated while running. Then > > Application.onCreate() will also be called. > > You can differentiate this situation by the fact that in the first > invocation the Bundle passed to onCreate() is null. When the activity > is recreated onCreate receives a copy of the intent given to > onSaveInstanceState() before onStop() is called. > > -- > "The flames are all long gone, but the pain lingers on" > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

