mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

MapView#onStop(), MapView#onDestory()

Open mrfaa opened this issue 9 years ago • 10 comments

**Platform: Android compileSdkVersion 25 **Mapbox SDK version: mapbox-android-sdk:5.1.0-SNAPSHOT@aar

With the latest Mapbox Version I get sometimes this exception: Fatal Exception: java.lang.RuntimeException: Unable to destroy activity {xxx}: java.lang.IllegalStateException: MapView#onStop() was not called. You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}.

I consider all lifecycle methods correctly. Before that version, this exception did not appear.

In the MapView.java file there is a TODO at the onDestroy method:

 @UiThread
  public void onDestroy() {
    if (!onStopCalled) {
      // TODO: 26/10/16, can be removed after 5.0.0 release
      throw new IllegalStateException("MapView#onStop() was not called. "
        + "You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}.");
    }

Is there a relation between these two points?

mrfaa avatar May 08 '17 09:05 mrfaa

@mrfaa thank you for reaching out and reporting your problem. Are you using Mapbox in a fragment? Could you check if you have overridden onStop in your Activity/Fragment and call into the MapView#onStop?

Since 5.0.0 it's required to hook into onStart/onStop instead of the previous onResume/onPause to correctly manage Location updates with multi window support in Android Nougat.

tobrun avatar May 08 '17 09:05 tobrun

Hi @tobrun thanks for your answer.

No, i don't have a fragment. I'm using the Mapview in an LinearLayout in an Activity. I don't have overridden the onStop method.

mrfaa avatar May 08 '17 10:05 mrfaa

What you are seeing is wanted behaviour. We want to make it crash when the developer has forgotten to hook into the newly added onStart/onStop. Adding those will resolve your issue. As mentioned above, those methods are required for proper support of Android Nougat.

tobrun avatar May 08 '17 10:05 tobrun

Sry, i want to say that i have considered all mapview lifecycle methods, also the onStart and onStop methods:

@Override
protected void onStart() {
  super.onStart();
  mapView.onStart();
}

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

But, i know the issue now: I forgot to change the telemetry service package from

// 4.x.x
<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService"/>

to

// 5.0.0
<service android:name="com.mapbox.services.android.telemetry.service.TelemetryService"/>

like mentioned in: https://github.com/mapbox/react-native-mapbox-gl/issues/516

Thanks for your hints and feedback!!

mrfaa avatar May 08 '17 11:05 mrfaa

I have the same bug.

MateusCarvalho avatar Jun 08 '17 19:06 MateusCarvalho

@MateusCarvalho Do you considered all things mentioned in https://github.com/mapbox/mapbox-gl-native/wiki/Android-4.x-to-5.0-update ?

mrfaa avatar Jun 09 '17 11:06 mrfaa

Yes.

I have implemented all changes.

MateusCarvalho avatar Jun 09 '17 11:06 MateusCarvalho

@MateusCarvalho Also the manifest changes mentioned above? Can you please post your error log?

mrfaa avatar Jun 09 '17 11:06 mrfaa

@mrfaa

 FATAL EXCEPTION: main
                                                             Process: com.app, PID: 23714
                                                             java.lang.RuntimeException: Unable to destroy activity {com.app/com.app.MainActivity}: java.lang.IllegalStateException: MapView#onStop() was not called. You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}.
                                                                 at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3849)
                                                                 at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3867)
                                                                 at android.app.ActivityThread.access$1500(ActivityThread.java:153)
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5451)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                              Caused by: java.lang.IllegalStateException: MapView#onStop() was not called. You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}.
                                                                 at com.mapbox.mapboxsdk.maps.MapView.onDestroy(MapView.java:279)
                                                                 at com.app.MainActivity.onDestroy(MainActivity.java:787)

MateusCarvalho avatar Jun 09 '17 17:06 MateusCarvalho

I think, that is because, in MainActivity I have a condition in onCreate, after setContentView, that when is true, I Start other activity and finish() the MainActivity.

MateusCarvalho avatar Jun 09 '17 17:06 MateusCarvalho