This question already has an answer here:
I want to send Following ArrayList from one activity to another please help.
ContactBean m_objUserDetails = new ContactBean();
ArrayList<ContactBean> ContactLis = new ArrayList<ContactBean>();
I am sending the above arraylist after adding data in it as follows
Intent i = new Intent(this,DisplayContact.class);
i.putExtra("Contact_list", ContactLis);
startActivity(i);
But I am getting problem while recovering it.
ArrayList<ContactBean> l1 = new ArrayList<ContactBean>();
Bundle wrapedReceivedList = getIntent().getExtras();
l1= wrapedReceivedList.getCharSequenceArrayList("Contact_list");
At this point I am getting this error:
Type mismatch: cannot convert from ArrayList<CharSequence> to ArrayList<ContactBean>
My ContactBean class implements Serializable please also tell why we have to implement serializable interface.
You can pass an
ArrayList<E>
the same way, if theE
type isSerializable
.You would call the
putExtra (String name, Serializable value)
ofIntent
to store, andgetSerializableExtra (String name)
for retrieval.Example:
In the other Activity:
Use this code to pass
arraylist<customobj>
to anthother Activityfirstly serialize our contact bean
Now pass your arraylist
you need implements Parcelable in your
ContactBean
class, I put one example for you:and this get and set for your code:
second class:
In First activity:
In receiver activity: