This question already has an answer here:
I need to pass a class object to another activity via intent. Here is my class code:
public class Model
{
private String Name;
private ArrayList<Trim> trim;
public String getName()
{
return Name;
}
public void setName(String Name)
{
this.Name = Name;
}
public ArrayList<Trim> getTrim()
{
return trim;
}
public void setTrim(ArrayList<Trim> trim)
{
this.trim = trim;
}
}
You need to implement
Serializable
in yourModel
class. Then, to pass aModel
object from sourceActivity
to destinationActivity
, use the following code in the sourceActivity
:And this code in the destination
Activity
:Your class should implement
Parcelable
interface and then you can send it to anotherActivity
using:To pass an object to another activity you need to implement Parcelable.
Review Writing Parcelable classes for Android carefully. Here they are using Hashmap to store the values and pass the object to another class.
OR
Make one class,
ObjectA
. In that, I used all the setter and getter methods.Then make one Activity that is used to send the Object to another activity.
Now finally make one another activity that read the Object and get the value from that.