2012-10-08 54 views
0

我试图将数据存储到包中并开始一个新的活动。然后在新的活动中,我想要取消数据。为铸造部分的代码是follwing:通过意向传递一个包

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[{param1={position=0, image=2130837504, flag=/data/data/com.example.app/cache/wpta_0.jpeg, price=Brand : Dash Price : 27}}] 

我怎样才能检索到上述数据为第二活动?我正在使用下面的代码块,但我无法访问属性。

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

你是什么意思,你不能访问属性?当你尝试索引HashMap中的数据时会发生什么? –

回答

2

我不相信你需要创建一个包通过一个串行化,简单地说了Serializable直入意图演员:

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

或者如果必须使用中间捆绑,请查看文档Bundle#putExtras(Bundle bundle)

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