...
It's a static reference, ie global to the process. So as activities
are started the ref points to the new activity.
That said, I agree the right thing to do here isn't obvious. But it's
also not obvious to me why you think it's bad to unregister the
listener in your apps onDestroy. I
Hm, so I just peeked at the source code of the Google Maps app on
Android, because they seem to get it right: if you have GPS enabled,
then it will stay on if the main Maps activity is hidden by another
activity of the same app, e.g. the Maps history screen, but it will
turn off when pausing the
okay, so sActivityReference is a java.lang.ref.WeakReference, so
apparently this is related to something else (memory management stuff
I guess?).
Any other ideas?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups
I found a workaround, but it's a hack, so I'm still open for better
ideas. I found this to do exactly what I need:
in the main activity of my app:
@Override
protected void onPause() {
super.onPause();
ActivityManager am = (ActivityManager) getSystemService
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
Well, I need to disable the listeners when the app goes into the
background, not only when it terminates.
I also tested this use of WeakReference, simply to see how it behaves,
and it didn't work for me at all. Regardless of whether the app was
paused to display another application or to display
Could you use a timer to introduce a short delay for the deactivation
of the listeners? For example by wrapping the calls to LocationManager
in a utility accessible from both your activities. If activity A is
paused by activity B, activity B would then get focus before the timer
expires and could
I also tested this use of WeakReference, simply to see how it behaves,
and it didn't work for me at all. Regardless of whether the app was
paused to display another application or to display another activity
of the same app, the identity test for 'this' always succeeded.
WeakReferences only
8 matches
Mail list logo