android Intent 如何传递 hashmap

For example, when sending the intent:

HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("key", "value");
Intent intent = new Intent(this, MyOtherActivity.class);
intent.putExtra("map", hashMap);
startActivity(intent);

And then in the receiving Activity:

protected void onCreate(Bundle bundle) {    super.onCreate(savedInstanceState);    Intent intent = getIntent();    HashMap<String, String> hashMap = (HashMap<String, String>)intent.getSerializableExtra("map");    Log.v("HashMapTest", hashMap.get("key"));
}


若文章对您有帮助,帮忙点个赞!

0
-5
发布时间 2022-03-29 00:06:41
0 条回复(回复会通过微信通知作者)
点击加载更多评论
登录 后再进行评论
(微信扫码即可登录,无需注册)