I have a static arraylist as I need to access this arraylist from other classes, however as this is static, I cannot use object serialization. Can anybody recommend an alternative to either serialization, or modifying my arraylist so I can use it in other classes?
Thanks
I face same problem, firstly if you are using a custom model class for arraylist make that custom class parcable you can see the links below to make a custom class parcable
1. how to make a model class parcable
after making the model class parcable use object of this class with bundle and then bundle with intent to some other class like
/**
* functionDescList is your array list of DeviceFunctionModel class type
*
*/
Intent intent=new Intent(mContext,DeviceOptions.class);
Bundle bundle= new Bundle();
bundle.putParcelableArrayList("DeviceFunctionModel", functionDescList);
intent.putExtras(bundle);
mContext.startActivity(intent);
//in calling class just get the parcelable arraylist
Bundle bundle=getIntent().getExtras();
ArrayList<DeviceFunctionModel>functionDescList=bundle.getParcelableArrayList("DeviceFunctionModel");
Second option is just make the model class implement Serializable and send it along with bundle with serialaizableArraylist and get in calling class
but i will prefer first option as it is fast and recommended in android
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.