From 9e45657a9837de66851752470415ddcd8961f703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=A4=A9=E4=BC=9F?= Date: Tue, 22 Aug 2023 16:24:36 +0800 Subject: [PATCH] * fix #620 bug and #864 bug --- .../com/lyokone/location/LocationPlugin.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/location/android/src/main/java/com/lyokone/location/LocationPlugin.java b/packages/location/android/src/main/java/com/lyokone/location/LocationPlugin.java index e6c765ac..33772071 100644 --- a/packages/location/android/src/main/java/com/lyokone/location/LocationPlugin.java +++ b/packages/location/android/src/main/java/com/lyokone/location/LocationPlugin.java @@ -84,7 +84,9 @@ public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBindin @Override public void onServiceConnected(ComponentName name, IBinder service) { Log.d(TAG, "Service connected: " + name); - initialize(((FlutterLocationService.LocalBinder) service).getService()); + if(service instanceof FlutterLocationService.LocalBinder){ + initialize(((FlutterLocationService.LocalBinder) service).getService()); + } } @Override @@ -114,12 +116,14 @@ private void dispose() { methodCallHandler.setLocationService(null); methodCallHandler.setLocation(null); - activityBinding.removeRequestPermissionsResultListener(locationService.getServiceRequestPermissionsResultListener()); - activityBinding.removeRequestPermissionsResultListener(locationService.getLocationRequestPermissionsResultListener()); - activityBinding.removeActivityResultListener(locationService.getLocationActivityResultListener()); + if(locationService != null){ + activityBinding.removeRequestPermissionsResultListener(locationService.getServiceRequestPermissionsResultListener()); + activityBinding.removeRequestPermissionsResultListener(locationService.getLocationRequestPermissionsResultListener()); + activityBinding.removeActivityResultListener(locationService.getLocationActivityResultListener()); - locationService.setActivity(null); + locationService.setActivity(null); - locationService = null; + locationService = null; + } } }