Passing custom objects between activities?

Using Parcelable interface you can pass custom java object into the intent.

1) implement the Parcelable interface to your class like:

class Employee implements Parcelable
{
}

2) Pass the Parcelable object into the intent like:

Employee mEmployee =new Employee();
Intent mIntent = new Intent(mContect,Abc.class);
mIntent.putExtra("employee", mEmployee);
startActivity(mIntent);

3) Get the data into the new [Abc] Activity like:

Intent mIntent  = getIntent();
Employee mEmployee  = (Employee )mIntent.getParcelableExtra("employee");

You should implement Parcelable interface.

Link to documentation.

Tags:

Java

Android