Cluster Manager Save Instance State
sshrop opened this issue · 2 comments
Is your feature request related to a problem? Please describe.
Throughout a Fragment's lifecycle, Android can be quite aggressive when destroying and recreating a fragment's view. It's almost certain to require instance state restoration when a user navigates from a fragment that hosts a MapView
.
In my case, I'm forced to recreate a ClusterManager
to redraw my markers when the host fragment is made visible again. Recreating custom markers can be a time consuming process, and a visual blip in the map can negatively affect the user experience.
Describe the solution you'd like
A first-class feature that allows the ClusterManger
to be rebound to a newly created map view, allowing for fast recovery of the MapView's state including all markers and state of interaction e.g. restoration of a visible item info window that was activated before the view was destroyed.
Describe alternatives you've considered
I haven't seen any documentation on how to handle UI state restoration. I'm wondering if I need to:
- Cache custom marker Bitmaps in memory
- Keep track of active item info windows
Additional context
Thanks in advance. I can provide additional context as needed to clarify my concern.
@sshrop you might check out the clustering ViewModel
demo. The clustering Algorithm
holds the marker state in the ViewModel
, which is retained across configuration changes. This allows for quickly restoring marker cluster state after a configuration change. The only state that should be updated is the view size, so the appropriate map view port is used.
Without a ViewModel
, marshalling all marker objects through onSaveInstanceState
would be difficult, as ClusterItem
s aren't required to be Parcelable
. Retaining the ClusterItem
marker objects is faster than serializing and deserializing them through saved instance state as well.