> 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 become null when there is a GC and no non-weak
refs exist.

> 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?

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 am skeptical battery life would be
that badly harmed?
--~--~---------~--~----~------------~-------~--~----~
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