I am trying to pass a custom object to one activity from another.
There is a guide that I am using that can be found here:

http://developer.android.com/guide/appendix/faq/framework.html

What I would like to use is the HashMap of WeakReferences, but the
description isn't clear, at least to me.

>From above URL:
"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."


My poor attempt:

MyObject object = new MyObject();
HashMap map = new HashMap();
WeakReference reference = new WeakReference(object);
map.put(reference.hashCode(), reference);

Intent i =  new Intent(myIntent);
i.putExtra(map);

I know this is probably way off but I can't figure out how this is
intended to be implemented based on the description.  Are the keys
hashcodes, user defined, or what?  It sounds like all that is passed
is a HashMap containing the key values but how is the object retrieved
with just the key?  I couldn't find any code examples or useful
documentation on this method of passing objects so any help would be
greatly appreciated.

Thanks,

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