Is there a way to pass an ArrayList <ArrayList<Integer>> floors
to another activity through Bundle?
Thanks
Is there a way to pass an ArrayList <ArrayList<Integer>> floors
to another activity through Bundle?
Thanks
Is there a way to pass an ArrayList > floors to another activity through Bundle?
Unfortunetly not.
If you would have ArrayList
without nested it will work with putIntegerArrayList(key, value)
and getIntegerArrayList(key)
.
But there is for sure another approach(es).I will explain you one possible way.
You can create class that will implement Serializable interface and in this class just create field and appropriate getter. I will give you basic example. Then you will pass Serializable through Activities.
public class DataHelper implements Serializable {
private ArrayList<ArrayList<Integer>> floors;
public DataHelper(ArrayList<ArrayList<Integer>> floors) {
this.floors = floors;
}
public ArrayList<ArrayList<Integer>> getList() {
return this.floors;
}
}
Save it to Bundle:
Bundle b = new Bundle();
b.putSerializable("floors", new DataHelper(floors));
and retrieve in target Activity:
getIntent().getExtras().getSerializable("floors");
To pass the arraylist from first activity to second activity.
Intent intent = new Intent(context, SecondActity.class);
intent.putIntegerArrayListExtra("arraylist",integerList); //integerList is ArrayList<Integer>
startActivity(intent);
To get the arrayList in second Activity.
ArrayList arrayList<Integer> = getIntent().getIntegerArrayListExtra("arraylist")
Read here.
If you want to pass the custom object between activities then read this thread.