Android hangs on ViewGroup.removeAllViews () using MapView

I have com.google.android.gms.maps.MapViewone that I create dynamically using

mapView = new MapView(DataManager.getInstance().getContext());

This mapView binds to the parent through addView(mapView). Somewhere later in my program I want to delete this mapView by calling parent.removeAllViews();, but there the android just nods. The application is completely frozen, and I have no idea why. What can I do to solve this problem?

Edit:

I did some more research using 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();
    }
}

remove , , . onPause , onDestroy . onCreate(), onResume(), . onDestroy() onPause() , removeView(child) . , , onPause . - , , , ?

: , , public void onInfoWindowClick(final Marker marker) {. , runOnUiThread().

+4
1

, , , , . , , -, . , -, MapView.onPause()

@Override
    public void onInfoWindowClick(final Marker marker) {

. . , :

@Override
public void onInfoWindowClick(final Marker marker) {
    new Handler().postDelayed(
            new Runnable() {
                @Override
                public void run() {
                    MainActivity.getInstance().runOnUiThread(
                            new Runnable() {
                                @Override
                                public void run() {
                                    myMethods();
                                }
                            });
                }
            }, 1);

. Google (https://code.google.com/p/gmaps-api-issues/issues/detail?id=8681).

+2

Source: https://habr.com/ru/post/1609450/


All Articles