diff --git a/audio_service/CHANGELOG.md b/audio_service/CHANGELOG.md index 22edaf91..5d05cbd4 100644 --- a/audio_service/CHANGELOG.md +++ b/audio_service/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.18.4 * Fix Android FlutterJNI error after quick relaunch. +* Fix Android NPE when destroying additional FlutterEngines. ## 0.18.3 diff --git a/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServicePlugin.java b/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServicePlugin.java index c9a57f69..b4143bc7 100644 --- a/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServicePlugin.java +++ b/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServicePlugin.java @@ -116,7 +116,6 @@ public static synchronized void disposeFlutterEngine() { private static final String CHANNEL_CLIENT = "com.ryanheise.audio_service.client.methods"; private static final String CHANNEL_HANDLER = "com.ryanheise.audio_service.handler.methods"; - private static Context applicationContext; private static final Set clientInterfaces = new HashSet<>(); private static ClientInterface mainClientInterface; private static AudioHandlerInterface audioHandlerInterface; @@ -189,6 +188,7 @@ static AudioHandlerInterface audioHandlerInterface() throws Exception { // INSTANCE FIELDS AND METHODS // + private Context applicationContext; private FlutterPluginBinding flutterPluginBinding; private ActivityPluginBinding activityPluginBinding; private NewIntentListener newIntentListener; @@ -270,7 +270,9 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) { clientInterface.setContext(null); clientInterface = null; applicationContext = null; - if (audioHandlerInterface != null) { + if (audioHandlerInterface != null + && audioHandlerInterface.messenger == flutterPluginBinding.getBinaryMessenger()) { + System.out.println("### destroying audio handler interface"); audioHandlerInterface.destroy(); audioHandlerInterface = null; }