Android application: showing overlay items in AsyncTask-Collection of common programming errors
As said by the other answers you can solve your problem using onSaveInstanceState(Bundle outstate) and onRestoreInstanceState(Bundle savedInstanceState) or even disabling orientation changes in the device.
Lets see one by one:
-Disabling orientation changes, may result in a pour user experience, so I would not favour it.
-Using onSaveInstanceState(Bundle outstate) and onRestoreInstanceState(Bundle savedInstanceState) you have two main oprions …
Option 1:
You can save only basic information about items being displayed (i.e. if it’s a map, you could save map center location and zoom) and then retrieve again from the database all the overlays information. That’s very simple but it may bacome very slow if you have several hundred of overlay items to retrieve, resulting again in a pour user experience.
Option 2:
You could use parcelable to extend you overlay Item so you could save all the overlay items during onSaveInstanceState(Bundle outstate), and restore them without reloading from database. I’ve used this for with several thousand of items, and it works quite well.
You can find parcelable information in here: Google and and example in here: Android – Parcel data to pass between Activities using Parcelable classes
Good luck