Reputation: 6450
I am passing an ArrayList of Items from one activity to another using a bundle. I am not getting any errors, but the Items do not display in my second activity. Am I implementing the getSerializable() and putSerializable() correctly?
Here is a snippet from my first Activity
ListArray Declared
ArrayList<Item> items = new ArrayList<Item>();
Where the items are put into a bundle
Intent ListIntent = new Intent(home.this, SectionListExampleActivity.class);
Bundle loadInfo = new Bundle();
loadInfo.putSerializable("items", items);
ListIntent.putExtras(loadInfo);
Second Activity
Bundle loadInfo = getIntent().getExtras();
items = (ArrayList<Item>) loadInfo.getSerializable("items");
I have implemented Serializable in both activities. I have ensured that the ArrayList does get populated in the first activity
Upvotes: 2
Views: 19871
Reputation: 14765
Just a guess: have you tried to serialize an array of Item (Item[]) instead of ArrayList. I am not shure if ArrayList is serializable.
loadInfo.putSerializable("items", items.toArray());
Bundle loadInfo = getIntent().getExtras();
items = (Item[]) loadInfo.getSerializable("items");
Upvotes: 2
Reputation: 110
Item class :
public class Item implements Serializable
In first Activity :
Intent intent = new Intent(this, Activity2.class);
intent.putExtra("items", items);
startActivity(intent);
In Second Activity (Activity2):
ArrayList<Item> items = (ArrayList<Item>) getIntent().getExtras()
.getSerializable("items");
Upvotes: 1