Save data and change orientation

If you have small data, you can save and restore it using onSavedInstanceState and onRestoreInstanceState .. for details go through this link Saving data

But in case, you have large data then I must say, you should not allow for the orientation changes(which force your activity to recreate). You can restrict it by adding below line in manifest file :

android:configChanges="orientation|keyboardHidden" // fixes orientation

See onSaveInstanceState(Bundle) and onRestoreInstanceState(Bundle)


I recommend this post

http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html

to anyone who is still looking for a solution to this problem. The author describes how to use a Fragment to retain data.

Make sure to have the call

setRetainInstance(true);

in the onCreate() method of your Fragment!