简体   繁体   中英

Android Passing hashtable from two activities

I want to pass this structure from intent A to intent B: Hashtable> parsedData;

I do this: //intent A

Intent intent = new Intent(A.this,B.class);
intent.putExtra("placemarkOnMap", placemarkOnMap);`

//intent B

Serializable data = getIntent().getSerializableExtra("placemarkOnMap"); 
placemarkOnMap = new Hashtable<String, Hashtable<String,String>> ((Hashtable<String, Hashtable<String,String>>)data); 

This return placemarkOnMap = {} but placemarkOnMap is not empty in the activity A.

What is wrong? Thanks.

You don't need to create a new Hashtable and initialize it with the one you get from the intent. This:

  placemarkOnMap = new Hashtable<String, Hashtable<String,String>> ((Hashtable<String, Hashtable<String,String>>)data);

can be replaced with :

placemarkOnMap = (Hashtable<String, Hashtable<String,String>>)data;

Other than that, make sure your Hashtable has values in it right before you put it in the intent. Since somethin gets deserializd for the "placemarkOnMap" that means you've put something there, but it was empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM