Lyokone / flutterlocation

A Flutter plugin to easily handle realtime location in iOS and Android. Provides settings for optimizing performance or battery.
MIT License
1.11k stars 826 forks source link

LocationPlugin.dispose crashes on configuration change handling #664

Open sergey-triputsco opened 2 years ago

sergey-triputsco commented 2 years ago

Plugin crashes on handling Android configuration change.

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'io.flutter.plugin.common.PluginRegistry$RequestPermissionsResultListener com.lyokone.location.FlutterLocationService.h()' on a null object reference
       at com.lyokone.location.LocationPlugin.dispose(LocationPlugin.java:20)
       at com.lyokone.location.LocationPlugin.detachActivity(LocationPlugin.java)
       at com.lyokone.location.LocationPlugin.onDetachedFromActivityForConfigChanges(LocationPlugin.java)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.detachFromActivityForConfigChanges(FlutterEngineConnectionRegistry.java:57)
       at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach(FlutterActivityAndFragmentDelegate.java:48)
       at io.flutter.embedding.android.FlutterActivity.release(FlutterActivity.java:7)
       at io.flutter.embedding.android.FlutterActivity.onDestroy(FlutterActivity.java:11)

Crash happens on the next OS versions Android 9, 10, 11, 12.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jasoncfpl commented 2 years ago

I have the error too。 location version:4.3.0 E/AndroidRuntime(20904): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'io.flutter.plugin.common.PluginRegistry$RequestPermissionsResultListener com.lyokone.location.FlutterLocationService.getServiceRequestPermissionsResultListener()' on a null object reference E/AndroidRuntime(20904): at com.lyokone.location.LocationPlugin.dispose(LocationPlugin.java:117) E/AndroidRuntime(20904): at com.lyokone.location.LocationPlugin.detachActivity(LocationPlugin.java:56) E/AndroidRuntime(20904): at com.lyokone.location.LocationPlugin.onDetachedFromActivityForConfigChanges(LocationPlugin.java:74) E/AndroidRuntime(20904): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.detachFromActivityForConfigChanges(FlutterEngineConnectionRegistry.java:375) E/AndroidRuntime(20904): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach(FlutterActivityAndFragmentDelegate.java:630) E/AndroidRuntime(20904): at io.flutter.embedding.android.FlutterActivity.release(FlutterActivity.java:622) E/AndroidRuntime(20904): at io.flutter.embedding.android.FlutterActivity.onDestroy(FlutterActivity.java:643) E/AndroidRuntime(20904): at android.app.Activity.performDestroy(Activity.java:8319) E/AndroidRuntime(20904): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1376) E/AndroidRuntime(20904): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5441) E/AndroidRuntime(20904): ... 15 more

metajet98 commented 2 years ago

same issue on version 4.3.0

Lyokone commented 2 years ago

Hello, can you try the latest 5.0.0 to see if it's still happen?

mulderpf commented 8 months ago

I arrived here since I just saw this issue in version 5.0.3. The app was closed and it went through all of the lifecycle changes and this happened when the lifecycle changed to detached.

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'io.flutter.plugin.common.PluginRegistry$RequestPermissionsResultListener com.lyokone.location.FlutterLocationService.h()' on a null object reference at com.lyokone.location.LocationPlugin.dispose(LocationPlugin.java:20) at com.lyokone.location.LocationPlugin.detachActivity(LocationPlugin.java) at com.lyokone.location.LocationPlugin.onDetachedFromActivityForConfigChanges(LocationPlugin.java) at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.detachFromActivityForConfigChanges(:37) at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach(:53) at io.flutter.embedding.android.FlutterActivity.onDestroy(:18) at android.app.Activity.performDestroy(Activity.java:8748) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1421) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5521) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5570) at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5874) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5789) at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2399) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loopOnce(Looper.java:238) at android.os.Looper.loop(Looper.java:357) at android.app.ActivityThread.main(ActivityThread.java:8094) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:957)