Java 通过意图传递包裹

Java 通过意图传递包裹,java,android,hashmap,Java,Android,Hashmap,我正在尝试将数据存储到一个包中,然后开始一个新的活动。然后在新活动中,我要取消数据广播。铸件的代码如下所示: Intent i = new Intent(MainActivity.this, ShowProductActivity.class); Bundle bundle = new Bundle(); // Getting adapter of the listview SimpleAdapter adapter = (SimpleAdapter ) mListView.getAdapter

我正在尝试将数据存储到一个包中,然后开始一个新的活动。然后在新活动中,我要取消数据广播。铸件的代码如下所示:

Intent i = new Intent(MainActivity.this, ShowProductActivity.class);
Bundle bundle = new Bundle();
// Getting adapter of the listview
SimpleAdapter adapter = (SimpleAdapter ) mListView.getAdapter();
bundle.putSerializable("param1",  ((HashMap<String, Object>) adapter.getItem(position)));
i.putExtras(bundle);
startActivity(i);
如何将上述数据检索到第二个活动中?我正在使用以下代码块,但无法访问属性

Bundle bundle = this.getIntent().getExtras();
HashMap<String, Object> param1 = (HashMap<String, Object>)bundle.getSerializable("param1");
Bundle Bundle=this.getIntent().getExtras();
HashMap param1=(HashMap)bundle.getSerializable(“param1”);

我不认为您需要创建一个包来传递一个可序列化文件,只需将可序列化文件直接放入Intent extras:

i.putExtras("param1", ((HashMap<String, Object>) adapter.getItem(position)));
i.putExtras(“param1”,((HashMap)adapter.getItem(position));

如果必须使用中间捆绑包,请查看文档以了解:

向意图中添加一组扩展数据。密钥必须包含一个包前缀,例如,应用程序com.android.contacts将使用类似“com.android.contacts.ShowAll”的名称


您不能访问属性是什么意思?当您尝试在HashMap中索引数据时会发生什么?
i.putExtras("param1", ((HashMap<String, Object>) adapter.getItem(position)));