Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

App crashes after closing mapView in fragment #10716

Closed

Description

@nijs9

**Platform:Android 7.0
**Mapbox SDK version:5.2.1

Steps to trigger behavior

  1. Create Mapview in Fragment
  2. Open mapview
  3. Close mapview

Expected behavior

Mapview closed

Actual behavior

App generates ANR and crashes after some seconds

If I grey out 'mapView.onDestroy()' the problem doesn't exists anymore. I'm testing on physical device (moto g5). I get no error exception in Android studio. App stops working after mapView.onDestroy(). This is my code:

`
public class PremiumRoutesMapFragment extends Fragment {

private MapView mapView;
private MapboxMap map;
private Icon iconnormal;
private Icon iconpremium;
private RouteParameter rp = null;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Mapbox.getInstance(getActivity(), getString(R.string.mapbox_access_token));

    rp = PremiumRoutes.rp;

    View root = inflater.inflate(R.layout.premium_routes_map_fragment, container, false);

    mapView = (MapView) root.findViewById(R.id.mapview);
    mapView.onCreate(savedInstanceState);

    // Add a MapboxMap
    mapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(final MapboxMap mapboxMap) {

            map = mapboxMap;

            LatLng startLocation = new LatLng();
            startLocation.setLatitude(51.01368);
            startLocation.setLongitude(4.20113);

            // Customize map with markers, polylines, etc.
            mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(startLocation, 7));


            mapboxMap.getUiSettings().setTiltGesturesEnabled(false);
            mapboxMap.getUiSettings().setRotateGesturesEnabled(false);
            mapboxMap.getUiSettings().setCompassEnabled(false);
            mapboxMap.setMaxZoomPreference(17);
            mapboxMap.setMinZoomPreference(1);

            mapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
                @Override
                public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {



                    if (marker.getTitle().equals("premiumroute") && Helper.hasAbo(getApplicationContext()) == false) {

                        Intent intent = new Intent();
                        intent.setClass(getApplicationContext(), NoSubscription.class);
                        Bundle b = new Bundle();
                        b.putInt("TYPE", 1);
                        intent.putExtras(b);
                        startActivity(intent);

                    }

                    else {

                        Intent intent = new Intent();
                        intent.setClass(getApplicationContext(), PremiumRouteDetails.class);
                        Bundle b = new Bundle();
                        b.putString("ROUTE", marker.getSnippet());
                        intent.putExtras(b);
                        startActivity(intent);
                    }


                    return true;

                }
            });


        }

    });

    return root;

}


@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

}

@Override
public void onStart() {
    super.onStart();
    mapView.onStart();

}

@Override
public void onResume() {
    super.onResume();
    mapView.onResume();
}

@Override
public void onPause() {
    super.onPause();
    mapView.onPause();
}

@Override
public void onStop() {
    super.onStop();
    mapView.onStop();
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mapView.onSaveInstanceState(outState);
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mapView.onLowMemory();
}

@Override
public void onDestroy() {
    super.onDestroy();
    mapView.onDestroy();

}


}

`

Activity

  1. tobrun commented on Dec 16, 2017

    @tobrun
    Member
    @Override
    public void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    needs to be replaced with:

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mapView.onDestroy();
    }

    This is noted in the javadoc of MapView#onDestroy()

  2. added
    Android
    on Dec 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Androidsupport

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions