Select to view content in your preferred language

When is it not safe to call MapView.getScale() and MapView.GetVisibleArea()?

1199
5
09-21-2018 06:55 PM
NathanMellor
Regular Contributor

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:

com.esri.arcgisruntime.internal.jni.CoreMapView.nativeGetScale (SourceFile)
com.esri.arcgisruntime.internal.jni.CoreMapView.q (SourceFile:233)
com.esri.arcgisruntime.internal.h.b.o.m (SourceFile:224)
com.esri.arcgisruntime.mapping.view.MapView.getMapScale (SourceFile:295)
....HomeActivity.updateZoomLevelText (BCHomeActivity.java:687)
...HomeActivity.access$000 (BCHomeActivity.java:203)
...HomeActivity$1.mapScaleChanged (BCHomeActivity.java:366)
com.esri.arcgisruntime.internal.h.b.n$1.run (SourceFile:58)

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. 

Tags (3)
0 Kudos
5 Replies
ShellyGill1
Esri Contributor

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 

0 Kudos
NathanMellor
Regular Contributor

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.


0 Kudos
ShellyGill1
Esri Contributor

> 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

0 Kudos
NathanMellor
Regular Contributor

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?

0 Kudos
NathanMellor
Regular Contributor

I did check and we do have calls to pause and dispose the mapview at the right time.

0 Kudos