Don't know where you read that, but it sounds somewhat bogus.  A
WeakHashMap had "weak" keys -- when the key object no longer exists
then the map entry is removed (eventually) by GC.  If you use a Long
as a key, and send the Long via intent extras, my understanding is
that the Long is apt to be serialized/deserialized, meaning that the
object received on the other end may not be the same Long.  The
problem with this is that the entry might be discarded before it is
accessed.

Now, you could use a HashMap of Long keys referencing WeakReferences,
but that would be a different beast.  Then the entries in the HashMap
would persist, but the object referenced could "evaporate" if the
original reference to it is "lost" on the sending side before the
receiving side retrieves the object.

In any event, the idea is that a reference to the (Weak)HashMap is
separately passed to the "other side", perhaps during initialization
of a background thread.  Then keys are passed via intents to identify
individual objects in the HashMap.  (Gotta admit that I don't quite
see the point in this either.)

On Oct 26, 5:11 pm, Anil <anil.r...@gmail.com> wrote:
> The FAQ mentions a method of passing objects around activities.
> (It is not clear to me):
>
> "A HashMap of WeakReferences to Objects
>
> You can also use a HashMap of WeakReferences to Objects with Long
> keys. When an activity wants to pass an object to another activity, it
> simply puts the object in the map and sends the key (which is a unique
> Long based on a counter or time stamp) to the recipient activity via
> intent extras. The recipient activity retrieves the object using this
> key."
>
> Trying to pass a StringBuilder to another activity,
>                        // trailBuilder is a StringBuilder
>                         WeakHashMap wkmap = new 
> WeakHashMap<String,StringBuilder>();
>                         wkmap.put("trailBuilder", trailBuilder);
>                         alertIntent.putExtra("trailBundle",wkmap); // compile 
> ERROR here
>
> Can anyone point me to an example of how this is done?
> thanks,
> Anil

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to