[android-developers] Re: Application.onPause()? Is there a hook like this?

2009-05-29 Thread matthias
... 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

[android-developers] Re: Application.onPause()? Is there a hook like this?

2009-05-28 Thread matthias
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

[android-developers] Re: Application.onPause()? Is there a hook like this?

2009-05-28 Thread matthias
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

[android-developers] Re: Application.onPause()? Is there a hook like this?

2009-05-28 Thread matthias
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

[android-developers] Re: Application.onPause()? Is there a hook like this?

2009-05-28 Thread Mike Hearn
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

[android-developers] Re: Application.onPause()? Is there a hook like this?

2009-05-28 Thread matthias
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

[android-developers] Re: Application.onPause()? Is there a hook like this?

2009-05-28 Thread HenrikH
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

[android-developers] Re: Application.onPause()? Is there a hook like this?

2009-05-28 Thread Mike Hearn
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