Hello All,
We are migrating out android app from 10.12 to 100.5.0, though almost 90% is completed. we have encountered a serious performance problem which leads to ANR and getting stuck of map view.
So here is the problem :
We have a rest API (normal json based,not feature layer) which expose an array of geo locations.our requirement is such that we have to call this api whenever the user moves or pans the map and draw the overlay of points (from the api response )in the current visible extent of the map using graphics overlay.
I have tried viewpointchangelistener() on the map view,the problem with that is the callback gets triggered so often,which results in unwanted api calls.also i have read from the document that this is not right place to do long operation.
then i have switched to navigationchangedlistener() and call the api if the map is not currently navigating on the current visible extent, though this has improved the performance considerably, still we have the problem.
here is the code that i use :
my navigation changed listener :
_mapView.addNavigationChangedListener(
navigationChangedEvent -> {
if (!navigationChangedEvent.isNavigating()) {
System.out.println("navigating");
if (_mapView.getMapScale() < 50000) {
mCurrentEnvelope = _mapView.getVisibleArea().getExtent();
getBusStopsList();
}
}
});
method which calls the API - getBusStopsList() :
private void getBusStopsList() {
System.out.println("calling busstops api ");
Envelope envelope = mCurrentEnvelope;
mBusRouteManager.getBusStopsList(
envelope.getXMin(),
envelope.getYMin(),
envelope.getXMax(),
envelope.getYMax(),
getLanguage(),
new BusRouteManager.BusStopsListener() {
@Override
public void onSuccess(List<Stop> ptStopList) {
System.out.println("recieved " + ptStopList.size() + " stops");
if (ptStopList.size() > 0) {
for (int i = 0; i < ptStopList.size(); i++) {
busStopHashMap.put(STOP_NAME, ptStopList.get(i).Name);
busStopHashMap.put(STOP_ID, ptStopList.get(i).Id);
busStopHashMap.put(STATELESS, ptStopList.get(i).Stateless);
busStopHashMap.put(STOP_DISPLAY_ID, ptStopList.get(i).DisplayId);
busStopHashMap.put(LAT, ptStopList.get(i).getLocation().getX());
busStopHashMap.put(LON, ptStopList.get(i).getLocation().getY());
busStopHashMap.put(OVERLAY_TYPE, BUS_STOPS_OVERLAY);
Point graphicPoint =
new Point(ptStopList.get(i).getLocation().getX(),
ptStopList.get(i).getLocation().getY());
Graphic stopGraphic =
new Graphic(
graphicPoint,
busStopHashMap,
busStopSymbol);
mBusStopsGraphicsOverlay.getGraphics().add(stopGraphic);
}
}
}
@Override
public void onFailure(String message) {
mDisplayUtils.showToast(message, MapActivity.this, Toast.LENGTH_SHORT);
}
});
}
This method internally makes a retrofit call to the api and onSuccess loops through the list and add the graphic to the overlay.
also this triggers lot of Garbage collecting activities and the respective logs gets printed in logCat.
when the app gets stuck, because of this issue. i get log saying that its tombstoned
I am sure that the issue is because of this method, when i comment this method from executing everything runs smoothly.
The same methodology was used in 10.2.9 which was working perfectly fine (we have earlier used scalechangedlistener() )
Please suggest some better approach regarding this issue.