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 cancel the timer to prevent the subscription from being removed. On the other hand, if activity A is paused by another application, the timer would expire and the listener properly deregistered. Could this solve your problem?
This is perhaps just as much of a hack as your above solution though... :) BR /Henrik On 28 Maj, 19:01, matthias <[email protected]> wrote: > 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 another activity > of the same app, the identity test for 'this' always succeeded. > > Frankly, I do not understand how this would work at all. In onCreate > (), the reference is set to 'this' (the current activity), otherwise > it is set to null. So the test for 'this' in onPause is only true, if > onPause() is called on the same activity instance that created the > weak reference in onCreate. But how could those ever be two distinct > objects? Is it possible that resuming an activity will not resurrect > the old one, but create a new activity object? But wouldn't that be > the same as simply doing an onCreate? I'm confused. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

