I want to pass a list of objects from one activity from another activity. I have one class SharedBooking Below:
public class SharedBooking {
public int account_id;
public Double betrag;
public Double betrag_effected;
public int taxType;
public int tax;
public String postingText;
}
Code from Calling activity:
public List<SharedBooking> SharedBookingList = new ArrayList<SharedBooking>();
public void goDivision(Context context, Double betrag, List<SharedBooking> bookingList) {
final Intent intent = new Intent(context, Division.class);
intent.putExtra(Constants.BETRAG, betrag);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
COde on called activity:
Bundle extras = getIntent().getExtras();
if (extras != null) {
amount = extras.getDouble(Constants.BETRAG,0);
}
How can I send the list of SharedBooking from one activity and receive that on other activity?
Please suggest me any usable link or sample code.
Parcelable object class
And the list
Code from Calling activity
Code on called activity
First, make the class of the list implement Serializable.
Then you can just cast the list to (Serializable). Like so:
And to retrieve the list you do:
That's it.
Use parcelable. Here is how you will do it:
Passing the data:
Retrieving the data:
You may want to implement the Parcelable Interface in your SharedBooking class and add them to the Intent i.e. with the putParcelableArrayListExtra Method. Check the documentation here:
http://developer.android.com/reference/android/content/Intent.html#putParcelableArrayListExtra%28java.lang.String,%20java.util.ArrayList%3C?%20extends%20android.os.Parcelable%3E%29