How to update MapView overlay items from an AsyncTask without ArrayIndexOutOfBoundsException

那年仲夏 提交于 2019-12-06 03:33:55

I think you must call postInvaliadate() of map view after updating overlays (after availableItemsOverlay.addOverlay(marker)).

Although onProgressUpdate() runs on the UI thread I am not sure if it is ment to be used to add overlay items. Instead, I recommend to add the overlay in onPostExecute(). The add() operation is not expensive since the list of items has already been generated at this point in time.

@Override
protected void onPostExecute(List<OverlayItem> overlay) {
  mMapView.getOverlays().add(overlay);
  mMapView.invalidate();
}

You need to change the signature of you AsyncTask to AsyncTask<Void, User, List<OverlayItem>> in order to match the method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!