I have a MapActivity
that contains a MapView
with some custom controls, state information开发者_C百科, 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:
- Some state information
- The ItemizedOverlay
- [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 Parcelable
in 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?
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.
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.
精彩评论