1

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

  • Possible duplicate of [How to serialize static data members of a Java class?](http://stackoverflow.com/questions/1008023/how-to-serialize-static-data-members-of-a-java-class) – Ramanlfc Mar 31 '16 at 11:02
  • You should explain what exactly your problem is. The common answer is *as static fields as not member of objects, there is no need to serialize them*. – Serge Ballesta Mar 31 '16 at 11:37

1 Answers1

0

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

2.doc parcable help

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

Community
  • 1
  • 1
Electro
  • 355
  • 3
  • 15