0

データをバンドルに保存して、新しいアクティビティを開始しようとしています。次に、新しいアクティビティでデータのキャストを解除します。鋳造部品のコードは次のとおりです。

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}}]

前述のデータを2番目のアクティビティに取得するにはどうすればよいですか?次のコードブロックを使用していますが、属性にアクセスできません。

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

1 に答える 1

2

1つのSerializableを渡すためにバンドルを作成する必要はないと思います。SerializableをIntentエクストラに直接配置するだけです。

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

または、中間バンドルを使用する必要がある場合は、次のドキュメントを確認してくださいBundle#putExtras(Bundle bundle)

拡張データのセットをインテントに追加します。キーにはパッケージプレフィックスを含める必要があります。たとえば、アプリcom.android.contactsは「com.android.contacts.ShowAll」などの名前を使用します。

于 2012-10-08T23:19:34.263 に答える