Android HashMap in Bundle?

Marcus Toepper picture Marcus Toepper · Jul 12, 2012 · Viewed 55.7k times · Source

The android.os.Message uses a Bundle to send with it's sendMessage-method. Therefore, is it possible to put a HashMap inside a Bundle?

Answer

ρяσѕρєя K picture ρяσѕρєя K · Jul 12, 2012

try as:

Bundle extras = new Bundle();
extras.putSerializable("HashMap",hashMap);
intent.putExtras(extras);

and in second Activity

Bundle bundle = this.getIntent().getExtras();

if(bundle != null) {
   hashMap = bundle.getSerializable("HashMap");
}

because Hashmap by default implements Serializable so you can pass it using putSerializable in Bundle and get in other activity using getSerializable