I’m tryin to store data into a bundle and the start a new activity. Then in the new activity I want to uncast the data. The code for for the casting part is the 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);
Generally, the data is contained into the bundle is as following:
Bundle[{param1={position=0, image=2130837504, flag=/data/data/com.example.app/cache/wpta_0.jpeg, price=Brand : Dash Price : 27}}]
How can I retrieve the aforementioned data into the second activity? I’m using the following block of code but I can’t access the attributes.
Bundle bundle = this.getIntent().getExtras();
HashMap<String, Object> param1 = (HashMap<String, Object>)bundle.getSerializable("param1");
I don’t believe that you need to create a Bundle to pass one Serializable, simply put the Serializable straight into the Intent extras:
Or if you must use the intermediate Bundle, check the documentation for
Bundle#putExtras(Bundle bundle):