I have a problem with saving an instance on screen orientation change. I have an array with a specific structure:
private ArrayList <MyObject> myArr;
And this sctructure is:
public MyObject{
public variable1;
//..... many variables here and one array :)
}
I need to save “myArr” array. How can I save this “variable”?
Basically, instance should be saved, using the way, described in Android Activity API Ref: you need to use
onSaveInstanceState(Bundle). Also, You can just setandroid:configChanges="orientation"in your manifest for an activity to prevent it’s recreation (so where won’t be any need for state saving presented).To save objects from the question in
onSaveInstanceState(Bundle)to the Bundle:MyObject(e.g. example can be found here etc.)onSaveInstanceState()and get back by getParcelableArrayList() inonCreate()after rotation;