I have a very strange problem. All I want to do is pass a LinkedHashMap<String,HashMap<String,String>>
(I am just experimenting here and the I would like the choice of data structure to remain unchanged regardless of performance overhead) object from one Activity to another via an Intent
. I tried two approaches after initializing and populating my data structure:
LinkedHashMap<String,HashMap<String,String>> mData = new LinkedHashMap<String,HashMap<String,String>>();
//insert data into LinkedHashMap
Approach 1:
Intent intent = new Intent(this, TestActivity.class);
// as a Serializable
intent.putExtra("DATA",mData)
startActivity(intent);
Approach 2:
Intent intent = new Intent(this, TestActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("LIST",mData);
intent.putExtra("DATA",bundle)
startActivity(intent);
And in the receiving Activity:
For Approach 1:
Intent intent = getIntent();
mData = (LinkedHashMap<String, HashMap<String, String>>) intent.getSerializableExtra("DATA");
For Approach 2:
Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("DATA");
mData = (LinkedHashMap<String, HashMap<String, String>>) bundle.getSerializable("LIST");
And I keep running into this issue:
Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to java.util.LinkedHashMap
at com.matchify.TestActivity.onCreate(TestActivity.java:56)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
What am I doing wrong ? Apologies if I have missed something very obvious.