As the other answers say, you can solve your problem using onSaveInstanceState (Bundle outstate) and onRestoreInstanceState (Bundle savedInstanceState) or even turn off orientation changes in the device.
Let's look one by one:
- Changing the orientation of orientation, can lead to the appearance of the user, so I would not approve of it.
-Using onSaveInstanceState (Conclusion abroad) and onRestoreInstanceState (Bundle savedInstanceState) you have two main applications ...
Option 1:
You can save only basic information about the displayed elements (i.e. if it is a map, you can save the location of the center of the map and the scale), and then again get all overlay information from the database. It is very simple, but it can be very slow if you have several hundred overlay elements to get them, which again will lead to a user experience.
Option 2:
You can use disassembly to expand your overlay element so that you can save all overlay elements during onSaveInstanceState (Bundle outstate) and restore them without rebooting from the database. I used this for several thousand items and it works quite well.
Here you can find comprehensive information: Google and an example here: Android - sending data for switching between actions using Parcelable classes
Good luck.
source share