I have a class called Service, which is used to create Service objects using this constructor
public Service(int id, String service_name, String service_code) {
this.id = id;
this.service_name = service_name;
this.service_code = service_code;
}
then I create a list call service list as with the following signature
List<Service> serviceList = new ArrayList<Service>
I have try to pass this ArrayList through Intent
Object like this
Intent i = new Intent(Classname.this, anotherClass.class);
i.putExtras("serviceList",serviceList);
startActivity(i);
But it fails. What is the way I pass through intent with ArrayList object.
You can use parcelable interface for 'Service' class, and send object through
intent using 'putParcelableArrayListExtra' method and to retrive data you can use
'getParcelableArrayListExtra'.
For your reference refer this link
Implement object class with Serializable . eg.
then try this code
and on other side receive intent like
Your custom class has to implement
Parcelable
orSerializable
in order to serialize/de-serialize within an Intent.Your class
Service
has to look like this for example (used a generator http://www.parcelabler.com/)}
Then you can use
getIntent().getParcelableArrayListExtra()
with castingFor sending you use it like this
Note that the
yourServiceArrayList
should be an ArrayListif it is List the you can pass through
intent.putParcelableArrayListExtra("list", (ArrayList<? extends Parcelable>) yourServiceArrayList);