开发者

What's the best way to save and restore a MapView in Android?

开发者 https://www.devze.com 2022-12-18 12:42 出处:网络
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 p

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:

  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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消