Android, How to place an ArrayList <myObject> in an intent?
If you make your Object Parcelabel class, you can pack your arraylist in the package that you send with the intent
see this link for an example
You typically use Bundle objects to pass information between actions, but they only allow simple type objects. As a rule, to transfer more complex types of objects, you usually have to create some kind of static context and set your own values ββfor it, which are then available for the second action. It feels dirty, but now I have it in my applications.
Your myObject class will need to implement Parcelable . Then you can use putParcelableArrayListExtra from your intent to pass it to the next action and get the list using getParcelableArrayListExtra
I used this.
set:
intent.putExtra("data", new DataWrapper(selectedTasks)); startActivity(intent); we get:
DataWrapper dw = (DataWrapper) getIntent().getSerializableExtra("data"); ArrayList<SelectedTask> taskList = dw.getList(); Arraylist object must be Serializable
public class SelectedTask implements Serializable{ } public class DataWrapper implements Serializable{ private ArrayList<SelectedTask> slist; public DataWrapper(ArrayList<SelectedTask> data) { this.slist = data; } public ArrayList<SelectedTask> getList() { return this.slist; } }