How to send hashmap value to another activity using an intent

后端 未结 2 1104
暖寄归人
暖寄归人 2020-11-30 22:51

How to send HashMap value from one Intent to second Intent?

Also, how to retrieve that HashMap value in the second Activity?

2条回答
  •  -上瘾入骨i
    2020-11-30 23:13

    I hope this must work too.

    in the sending activity

    Intent intent = new Intent(Banks.this, Cards.class);
    intent.putExtra("selectedBanksAndAllCards", (Serializable) selectedBanksAndAllCards);
    startActivityForResult(intent, 50000);
    

    in the receiving activity

    Intent intent = getIntent();
    HashMap> hashMap = (HashMap>) intent.getSerializableExtra("selectedBanksAndAllCards");
    

    when I am sending a HashMap like following,

    Map> selectedBanksAndAllCards = new HashMap<>();
    

    Hope it would help for someone.

提交回复
热议问题