i am trying to pass an arraylist back to my parent activity
Here is the simple code.
private ArrayList<Receipt> receipts = new ArrayList<Receipt>();
Intent data = new Intent();
data. // what to do here?
setResult(RESULT_OK, data);
//************************************
This is basic receipt Class
public class Receipt {
public String referenceNo;
public byte[] image;
public String comments;
public Date createdOn;
public Date updatedOn;
Tell me how can i add it in my intent and how can i retrieve it back in parent activity from
onActivityResult(final int requestCode, int resultCode, final Intent data)
You can use
data.putExtra()/bundle.putSerializable()to put custom objects in a Bundle/Intent, however, you have to make your class Receipt implementSerializable(just putimplements Serializableafter the class name, that’s all there is to it with such a simple class.Then to read it back you use
getSerializable().Note: I don’t think that the
Date-class is serializable, you might want to replace those with a long representing time in milliseconds instead ( you can useDate.getTime()for that).Example: