I wanted to pass arraylist of objects from one fragment to another i tried the following ways, wanted to know what are the pro's and con's of the following or is their any better approach
First
public myFragment(ArrayList<E> myarray) {
super();
this.myarray=myarray;
}
In the above code i created a constructor in the fragment class and used it to modify the arraylist but as i read from net this is not the best practice i searched for other's
Second
public static myFragment newInstance(ArrayList<E> myarray1) {
// TODO Auto-generated constructor stub
MyFragment myFragment=new MyFragment();
myarray=myarray1;
}
here i created a static method which modify's the static arraylist myarray
Third
public static myFragment newInstance(ArrayList<E> myarray1) {
// TODO Auto-generated constructor stub
MyFragment myFragment=new MyFragment();
Bundle bundle=new Bundle();
bundle.putSerializable(TAG,myarray1);
myFragment.setArguments(bundle);
return myFragment;
}
In this code i created a Serializable arraylist and passed it to bundel then
myarray=(ArrayList<E>) bundle.getSerializable(TAG);
retrived the arraylist from bundle
Fourth
the forth method which i got on net was using parcelable instead of Serializable but it was bit difficult to create a parcelable, if any one can share easy way to create a parceable as i have array list inside arraylist.
So which of them is best approach or is their any better approach to send custom object from one fragment to another and what are their pro's and con's