tags:

views:

99

answers:

2

I have a MapActivity that contains a MapView with some custom controls, state information, and an ItemizedOverlay composed by some locations that I draw using the default approach (using populate(), super.draw() and createItem()) and by some lines that I draw in the overrided draw() method.

So, when the activity is paused, I have to save:

  1. Some state information
  2. The ItemizedOverlay
  3. [Maybe more Overlays in the future.]

I'm saving the state information as usual, putting them in the bundle. I'm thinking in doing the same with the Overlays, implementing Parcelablein each one of the OverlayItems and so, but I don't know if there is a better way to store the complete state of the MapViews.

The information depends on remote requests that I don't want to repeat each time the activity is paused.

Any recommendation?

A: 

If all information regarding OverlayItems is obtained from remote request, the most simple solution would be to store last request output in a file.

On activity restart, you check if the cashed request output is available (and perhaps is still valid for your needs) and than use the existing methods to extract data from it.

For example, if you get POI's from remote KML or JSON, you can use the existing parser to extract data from local file as well.

Viktor Bresan
Yes, it's a good solution when you want to preserve the state for a long time. But our problem was with other cases in which `onPause` is called as orientation changes and so.
Jaime Soriano
A: 

As general solution onRetainNonConfigurationInstance() and getLastNonConfigurationInstance() with the complete Activity or with an array with the Objects of interest can be used. Then in onCreate() the View can be regenerated.

Jaime Soriano