That was actually my first approach, but I ran into problems when the screen orientation changed. I was removing the static references when the Activity was first created. So when the Activity was recreated (when the orientation changed), the static references were no longer there. I have yet to find a good way to allow the statics to stick around long enough for screen orientation changes, and ensure they get cleaned up when the Activity is closed for good.
I guess some sort of expiring cache could clear them if they weren't used within a certain time frame after onDestroy() was called. Another option might be to cache them based on the Activity instance after the Activity is first created, then clean them up later if that Activity is no longer displayed, or perhaps if it has been GCed. I'm not too fond of either of the above solutions. It seems like there must be a better way. Mark On Dec 8, 6:08 pm, Jason Proctor <[email protected]> wrote: > well you know the objects referred to by WeakReferences can disappear > at any time, that's the whole point of a WeakReference -- it's a > "cache" of sorts, the elements of which can be expired as and when > the VM needs the memory. > > if you particularly wanted to use the Map method, as opposed to any > of the other methods on that page, you could have a Map of regular > references, and clear the Map out when the receiving Activity has > retrieved what it needs from it. > > hth > J > > > > >I'm working on an application that requires non-serializable objects > >to be passed between Activities. The following page suggests using a > >HashMap of WeakReferences to accomplish this: > > >http://developer.android.com/guide/appendix/faq/framework.html > > >Is this solution safe? I know Activities are completely destroyed and > >recreated when the screen orientation changes. Couldn't those weakly > >referenced objects get GCed in the split second when the screen is > >rotated, since they wouldn't be referenced elsewhere at that point? > > >Thanks, > >Mark > > >-- > >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 > > -- > jason.vp.engineering.particle -- 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

