What is the best way to save and restore MapView in Android?

I have MapActivityone that contains MapViewwith some customizable controls, status information and ItemizedOverlayconsisting of some locations that I draw using the default approach (using populate(), super.draw()and createItem()) and some lines that I draw in the overridden method draw().

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

  • Some status information
  • ItemizedOverlay
  • [Perhaps more overlays in the future.]

I save status information as usual by putting them in a kit. I am thinking of doing the same with Overlays, implementing Parcelablein each of OverlayItemsand so, but I do not know if there is a better way to maintain the full state MapViews.

The information depends on the remote requests, which I do not want to repeat every time the action is paused.

Any recommendation?

+3
source share
2 answers

If all information about is OverlayItemsobtained from a remote request, the easiest solution would be to save the last request in a file.

When you reload an activity, you check to see if access to the cache exit is available (and perhaps it is still valid for your needs), and use existing methods to extract data from it.

, POI KML JSON, .

0

onRetainNonConfigurationInstance() getLastNonConfigurationInstance() Activity Objects. onCreate() View.

0

Source: https://habr.com/ru/post/1730873/


All Articles