We get some crash reports sometimes that we don't quite understand.
I understand that there are times when the MapView is not ready to return information like Scale and VisibleArea.
But how do I tell when it is safe? Crashing isn't very user friendly.
Example 1:
Sure there are times when the scale can't be read. But I don't think one of those times should be when you just called us to tell us the scale changed. That seems like a time when we can get a scale and update the zoomlevel. But nope, it crashes. Not all the time, but some of the time.
A bit ridiculous?
Is there some method available like boolean MapView isItSafetoAskforScale() ?
Because the only other alternative I can think of is to handle an exception every time we call MapView.getMapScale().
Or just let it crash.
Hi Nathan,
Can you share more details to help us reproduce this problem? I can access the MapView's scale OK in a MapScaleChangedListener, and I'm using ArcGIS Runtime SDK for Android 100.3. Let us know about your device, which version of Android you have, and ideally some simple code that shows the problem for you.
Regards,
Shelly
It occurs in Android 6-9
I do not have simple code to reproduce it. It does not happen all the time, but happens fairly often for actual users. If I knew what triggers it, I'd be closer to fixing it.
This code is in onCreate() of the activity.
mMapView.addMapScaleChangedListener(new MapScaleChangedListener() { @Override public void mapScaleChanged(MapScaleChangedEvent mapScaleChangedEvent) { updateZoomLevelText(); } }); This code is in a local method. Only important thing here is that we are calling getMapScale.private void updateZoomLevelText() { tvZoomLevel.setText(String.valueOf(BC_Helper.getZoomLevelByScale(mMapView.getMapScale()))); }Only thing that occurs to me is that somehow we are getting this event at a point in the Activity lifecycle
where the activity, and therefore the MapView, is no longer valid.
> Only thing that occurs to me is that somehow we are getting this event at a point in the Activity lifecycle
where the activity, and therefore the MapView, is no longer valid.
Perhaps something is hanging on to a callback when it should have been disposed - have you got calls to pause and dispose the MapView in the activities onPause and onDestroy methods (e.g. like shown here )? Let me know, and I will pass on this info and post back if we can find the cause or if there's a workaround.
Shelly
I cannot prove it, but I suspect this could be called after onDestroy and therefore
Does that sound likely?
Could the event handler get called if it is still in queue after the disposal?
I did check and we do have calls to pause and dispose the mapview at the right time.