Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't pass an ArrayList<Parcelable> to an activity

This is the code

ArrayList<MyObject> list = new ArrayList<MyObject>();
list.add(new MyObject());
Intent intent = new Intent(this, ReceiverActivity.class);
intent.putExtra("list", list);
startActivity(intent);

ReceiverActivity

List<MyObject> list = (List<MyObject>)getIntent().getExtras().getParcelable("list");

Here list is null. Also this doesn't work:

List<MyObject> list = (List<MyObject>)getIntent().getExtras().getSerializable("list");

MyObject is Parcelable, I implemented all required methods. I guess this implementation is not the problem, because otherwise I would recive other kind of exceptions. But I don't get anything besides list is null.

Thanks in advance...

Now I found this:

List<Parcelable> list = (List<Parcelable>)getIntent().getParcelableArrayListExtra("list");

that has to be used in the receiver activity, but how do I send it and how do I get List<MyObject> from List<Parcelable> ?

like image 245
User Avatar asked Jun 25 '12 13:06

User


2 Answers

USe i.putParcelableArrayListExtra(name, value) where i is your intent. Dont use putExtra() for a parcelable ArrayList.

like image 114
Akhil Avatar answered Oct 14 '22 03:10

Akhil


Try:

ArrayList<MyObject> myList = extras.<MyObject>getParcelableArrayList("list"));
like image 31
Mar Bar Avatar answered Oct 14 '22 05:10

Mar Bar