react-native-maps: Crashes when clicking back button to exit on Android

Hi, I use MapView as the main screen of the app and when I try exiting using the back button it crashes with the following error java.lang.NullPointerException: Attempt to invoke interface method 'void maps.af.y.q()' on a null object reference at maps.af.Q.d(Unknown Source) Anyone know how I can fix it? Thanks

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I can’t believe the issue is from Jul and still no progress made. I end up exiting the app from another view:

      BackAndroid.addEventListener('hardwareBackPress', () => {
       if (currentState === MAP_VIEW) {
         //  set to another state to render without the map or
         //  navigate to another scene without map view
         return true;
       }
       return false;
      });

Hi, This patch of AirMapView.java 0.8.2 works for me:

--- /Temp/0.8.2/AirMapView.java 2016-09-20 13:27:10.000000000 +0300
+++ node_modules/react-native-maps/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java  2016-09-20 10:43:01.000000000 +0300
@@ -86,6 +86,7 @@
     private LifecycleEventListener lifecycleListener;
     private OnLayoutChangeListener onLayoutChangeListener;
     private boolean paused = false;
+    private boolean destroyed = false;
     private ThemedReactContext context;

     final EventDispatcher eventDispatcher;
@@ -288,7 +289,10 @@
         if (!paused) {
             onPause();
         }
-        onDestroy();
+        if (!destroyed) {
+            destroyed = true;
+            onDestroy();
+        }
     }

     public void setRegion(ReadableMap region) {