I want send LinkedHashMap to another Intent. But I don't known what method for extras is allowable.
Bundle extras = getIntent().getExtras();
LinkedHashMap<Integer, String[]> listItems = extras.get(LIST_TXT);
I want send LinkedHashMap to another Intent. But I don't known what method for extras is allowable.
Bundle extras = getIntent().getExtras();
LinkedHashMap<Integer, String[]> listItems = extras.get(LIST_TXT);
You cannot reliably send a
LinkedHashMap
as anIntent
extra. When you callputExtra()
with aLinkedHashMap
, Android sees that the object implements theMap
interface, so it serializes the name/value pairs into the extrasBundle
in theIntent
. When you want to extract it on the other side, what you get is aHashMap
, not aLinkedHashMap
. Unfortunately, thisHashMap
that you get has lost the ordering that was the reason you wanted to use aLinkedHashMap
in the first place.The only reliable way to do this is to convert the
LinkedHashMap
to an ordered array, put the array into theIntent
, extract the array from theIntent
on the receiving end, and then recreate theLinkedHashMap
.See my answer to this question for more gory details.