Closed rashiq closed 11 years ago
It's an Android behavior where on device rotation, onCreate (and onCreateView) is called, effectively resetting your stuff back to when it's initialized. To counter it, simply override onSaveInstanceState function and save the data that need to persist to the state bundle. This bundle will be returned as a parameter variable in the onCreate/onCreateView function, where you can check and use the values inside that bundle to restore your persisting data.
Hey, Everytime I rotate my Application all Data gets deleted. For example in my public Fragment getItem(int position) I return a certain value for every Item Fragment in the Viewpager, but when I rotete the screen, the value is gone. I hope you could understand what I mean. Here is my code:
Now before rotating everything works well, so for the first fragment in the Viewpager the TextView shows "hi", for the second a 2, for the third a 3 etc... But when you rotate the screen, you'll just see the default value of the String mContent (which is "???" ). How can I prevent the Data I returned to be deleted?
Here are screenshots:
http://imgur.com/a/xpkdz