First you need to create a Parcelable object class, see an example
public class Student implements Parcelable { int id; String name; public Student(int id, String name) { this.id = id; this.name = name; } public int getId() { return id; } public String getName() { return name; } @Override public int describeContents() {
And the list
ArrayList<Student> arraylist = new ArrayList<Student>();
Code from the calling activity
Intent intent = new Intent(this, SecondActivity.class); Bundle bundle = new Bundle(); bundle.putParcelableArrayList("mylist", arraylist); intent.putExtras(bundle); this.startActivity(intent);
Code for the called activity
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); Bundle bundle = getIntent().getExtras(); ArrayList<Student> arraylist = bundle.getParcelableArrayList("mylist"); }
Shams source share