Bug with MapView.retainState() and MapView.restoreState()

2039
1
02-07-2013 02:10 PM
JohnBuckland
New Contributor
I'm experiencing what appears to be a bug with MapView retainState and/or restoreState. When I call retainState() I get back a string like the following "-1.2471800881220436E7 4953487.459564156 29.294122036046193 1". Now, since the meaning of this string is undocumented, I'm taking some guesses here, but that last "1" seems to indicate whether or not you have a location service running.

However, when you restart your activity and then call restoreState passing in that string, it seems to turn on your location service AND setAutoPan(true)!! It does this even if you never got a location service from the map, or if you got one and explicitly setAutoPan(false).

If the meaning of that last "1" is actual whether or not to autoPan, retainState seems to be setting it to 1 if you have a location service started at all, autoPan or not.

In my use case, I have a location service running, autoPan to false, and am calling retainState on onPause. I then call restoreState on 'map initialized' (listening for the maps onStatusChanged where status == STATUS.INITIALIZED). This forces autoPan on, with no way to turn it off.

My solution for now is to change that final "1" to a "0" before I store it in my local preferences, so that autoPan is not turned on when I restoreState. Please let me know if i'm "doing it wrong", of it any other information would be helpful.
0 Kudos
1 Reply
DanO_Neill
Occasional Contributor III
You are correct, the last item references whether the LocationService is started where 1 = on and 0 = off.  I have reproduced your issue and can confirm the return string from MapView.retainState() is not working as expected.  The best workaround I have is the one you suggest whereby you programmatically change the last item in the string to the value you want. 

A basic example:
        StringBuilder state = new StringBuilder(map.retainState());

        if (!locationService.isStarted()){
            state.deleteCharAt(state.length() - 1);
            state.append(0);
        }

        String updateState = state.toString();


We have logged a bug against this issue and look to fix for the next release.
0 Kudos