The Extras in an intent are key-value-pairs in a Bundle, which is actually a HashMap.
Java Code:
1
intent.putExtra("tests.test.MyApp.A.EXTRA_KEY", populateSelectedEntryList(selectedResultEntry));
In the above snippet, we are adding the key-value-pair of "tests.test.MyApp.A.EXTRA_KEY" (as the key) and the LinkedHashMap returned by populateSelectedEntryList(selectedResultEntry) (as the value) to that internal HashMap.
Now when we call startActivity with the intent containing that Extras Bundle, the Android system needs to convert that Bundle into Byte stream, i.e. serialize the Bundle (because (1) the Activity to be started might be started in another process, so the system serializes and then deserializes the objects in the Bundle, so that it can recreate them in the other process. (2) Android saves the contents of the intent in some system tables, so that it can recreate the intent later if needed).
So in the process of doing so, the system has to see what type the "values" in the extras' key-value-pairs are (in order to do the serialization in the most efficient way), by comparing them against a pool of known Object's ( like Integer, Long, String, Map, List, Bundle etc.), one of which is a Map. So the system finds out that the type of value is Map, so it serializes it and marks it as having the type Map.
When this value is deserialized in
Java Code:
1
LinkedHashMap dataHashMap = (LinkedHashMap) intent.getSerializableExtra("tests.test.MyApp.A.EXTRA_KEY");
Android converts that Map into a HashMap, and there is No way to change this behavior of Android. :-|
无法在Activity之间直接传递LinkHashMap看来是Android反序列化bundle的一个“bug”了,看来只能使用其他方式传递了,比如json