Android: How to keep an instance of activity when changing screen orientation? I use objects, not just variables

I have a problem saving an instance when changing screen orientation. I have an array with a specific structure:

private ArrayList <MyObject> myArr; 

And this is sctructure:

 public MyObject{ public variable1; //..... many variables here and one array :) } 

I need to save the array "myArr". How to save this "variable"?

0
source share
1 answer

Basically, the instance should be saved using the method described in the Android Activity Ref API : you need to use onSaveInstanceState(Bundle) . Alternatively, you can simply set android:configChanges="orientation" in your manifest for activity in order to prevent it from being recreated (so that where there will be no need to save state).

To save objects from a question in onSaveInstanceState(Bundle) in a Bundle:

+3
source

All Articles