Skip to content

Commit 81bba40

Browse files
committed
fix multiple unresponsive and unclosable overlays can be opened
1 parent 3a6fbeb commit 81bba40

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

android/src/main/java/flutter/overlay/window/flutter_overlay_window/FlutterOverlayWindowPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.net.Uri;
77
import android.os.Build;
88
import android.provider.Settings;
9+
910
import androidx.annotation.NonNull;
1011
import androidx.annotation.Nullable;
1112

@@ -110,7 +111,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
110111
} else {
111112
result.notImplemented();
112113
}
113-
114114
}
115115

116116
@Override

android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ public IBinder onBind(Intent intent) {
7676
public void onDestroy() {
7777
Log.d("OverLay", "Destroying the overlay window service");
7878
isRunning = false;
79+
if(windowManager != null && flutterView != null) {
80+
windowManager.removeView(flutterView);
81+
windowManager = null;
82+
}
83+
if(flutterView != null) {
84+
flutterView.detachFromFlutterEngine();
85+
flutterView = null;
86+
}
7987
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
8088
notificationManager.cancel(OverlayConstants.NOTIFICATION_ID);
8189
if(CachedMessageChannels.overlayMessageChannel != null){
@@ -90,20 +98,16 @@ public int onStartCommand(Intent intent, int flags, int startId) {
9098
mResources = getApplicationContext().getResources();
9199
boolean isCloseWindow = intent.getBooleanExtra(INTENT_EXTRA_IS_CLOSE_WINDOW, false);
92100
if (isCloseWindow) {
93-
if (windowManager != null) {
94-
windowManager.removeView(flutterView);
95-
windowManager = null;
96-
flutterView.detachFromFlutterEngine();
97-
stopSelf();
98-
}
99-
isRunning = false;
101+
stopSelf();
100102
return START_STICKY;
101103
}
102-
if (windowManager != null) {
104+
if(windowManager != null && flutterView != null) {
103105
windowManager.removeView(flutterView);
104106
windowManager = null;
107+
}
108+
if(flutterView != null) {
105109
flutterView.detachFromFlutterEngine();
106-
stopSelf();
110+
flutterView = null;
107111
}
108112
isRunning = true;
109113
Log.d("onStartCommand", "Service started");
@@ -128,7 +132,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
128132

129133
BasicMessageChannel<Object> overlayMessageChannel = new BasicMessageChannel<>(FlutterEngineCache.getInstance().get(OverlayConstants.CACHED_TAG).getDartExecutor().getBinaryMessenger(), OverlayConstants.MESSENGER_TAG, JSONMessageCodec.INSTANCE);
130134
overlayMessageChannel.setMessageHandler((message, reply) -> {
131-
if(CachedMessageChannels.mainAppMessageChannel == null) {
135+
if (CachedMessageChannels.mainAppMessageChannel == null) {
132136
reply.reply(false);
133137
return;
134138
}

0 commit comments

Comments
 (0)