Android ArrayList<MyObject> pass as parcelable Android ArrayList<MyObject> pass as parcelable android android

Android ArrayList<MyObject> pass as parcelable


I know this question is rather old but since I originally came here looking for answers, I wanted to share my experience.

Yes, you need to implement Parcelable for your Locality class but that is it.

If your LocalityList is ONLY a wrapper for ArrayList, then you do not need it.

Just use the putParcelableArrayList method.

ArrayList<Locality> localities = new ArrayList<Locality>;...Bundle bundle = new Bundle();bundle.putParcelableArrayList(KEY_LOCALITY_LIST, localities);fragmentInstance.setArguments(bundle);return fragmentInstance;

And retrieve it using...

localities = savedInstanceState.getParcelableArrayList(KEY_LOCALITY_LIST);

So, unless you need the custom ArrayList for some other reason, you can avoid doing any of that extra work and only implement Parcelable for your Locality class.


Yes, make Locality class itself Parcelable, and don't forgot to initialize

ArrayList<Locality> mList= new ArrayList<Locality>();


The trick i normally use is to parse the list to Json using Gson (from google). On the other side i just parte the string in Json back to a new list.

Never noticed any lag.