I've got a com.google.android.gms.maps.MapView
that I create dynamically, using
mapView = new MapView(DataManager.getInstance().getContext());
This mapView gets attached to a parent through addView(mapView)
. Somewhere later in my program, I want to remove this mapView by calling parent.removeAllViews();
, but there android just stalls. The app freezes completely, and I've got no idea why. What can I do to resolve this?
Edit:
I have done some more research using a CustomMapView
:
import android.content.Context;
import android.view.View;
import com.google.android.gms.maps.MapView;
/**
* @author Daniël van den Berg
* @date 9/30/2015.
*/
public class CustomMapView extends MapView {
public CustomMapView(Context context) {
super(context);
}
@Override
public void onViewRemoved(View child) {
super.onViewRemoved(child);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
}
public void remove() {
onPause();
onDestroy();
}
}
I call the remove method before trying to remove the view, and that's where it hangs. The breakpoint at onPause does get triggered, but the one at onDestroy doesn't. I call both onCreate()
and onResume()
when it gets created. Calling onDestroy()
without calling onPause()
does work, though then removeView(child)
hangs again. So apparently onPause is hanging my app. Does anybody have any ideas on what I could do to figure out what the problem is?
Edit:
Yet another addition, this problem only seems to occur when the map is removed from public void onInfoWindowClick(final Marker marker) {
. In this function I call the method that removes the view through runOnUiThread()
.