There is an Application.onCreate() and an Application.onDestroy() you
can use. These are not guaranteed to be called when your app isn't
visible, in fact destroy isn't guaranteed to be called at all, but
that's OK for your use case.

Apparently, the way Maps is doing it is they set a weak ref in onCreate
() then check it in onPause/onDestroy. The idea, I suppose, is that
the activity transition goes:

startActivity
onCreate of new activity
onPause of existing activity
onResume of new activity

So if onCreate sets a static ref to itself, then onPause can check if
it points at "this" to know if the next activity is another instance
of the same thing. You could do the same trick with something stashed
in your application object. It has to be a WeakRef because otherwise
this will leak the foreground activity (a weak ref is just like a
pointer, but it doesn't stop the target being garbage collected. so it
can spontaneously become null).
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to