Unable to pass ArrayList <Parcelable> to action

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 the list is null. Also this does not work:

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

MyObject Parcelable, I performed all the necessary methods. I assume this implementation is not a problem, because otherwise I would take advantage of other exceptions. But I get nothing except that the list is null.

Thanks in advance...

Now I have found this:

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

which should be used in receiver activity, but how do I send it and how do I get it List<MyObject>from List<Parcelable>?

+5
source share
2 answers

USe i.putParcelableArrayListExtra(name, value)where I intend. Do not use putExtra () for an arbitrary ArrayList array.

+15

Try:

ArrayList<MyObject> myList = extras.<MyObject>getParcelableArrayList("list"));
+6

All Articles