Android HashMap in Bundle?

后端 未结 7 2392
眼角桃花
眼角桃花 2020-12-02 11:57

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

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 12:21

    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

提交回复
热议问题