Skip to content

Commit 768c5cf

Browse files
committed
fix multiple unresponsive and unclosable overlays can be opened
1 parent 13f68fb commit 768c5cf

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
133133
} else {
134134
result.notImplemented();
135135
}
136-
137136
}
138137

139138
@Override

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ public IBinder onBind(Intent intent) {
7878
@Override
7979
public void onDestroy() {
8080
Log.d("OverLay", "Destroying the overlay window service");
81-
if (windowManager != null) {
81+
isRunning = false;
82+
if(windowManager != null && flutterView != null) {
8283
windowManager.removeView(flutterView);
8384
windowManager = null;
85+
}
86+
if(flutterView != null) {
8487
flutterView.detachFromFlutterEngine();
8588
flutterView = null;
8689
}
87-
isRunning = false;
8890
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
8991
notificationManager.cancel(OverlayConstants.NOTIFICATION_ID);
9092

@@ -104,20 +106,16 @@ public int onStartCommand(Intent intent, int flags, int startId) {
104106
int startY = intent.getIntExtra("startY", OverlayConstants.DEFAULT_XY);
105107
boolean isCloseWindow = intent.getBooleanExtra(INTENT_EXTRA_IS_CLOSE_WINDOW, false);
106108
if (isCloseWindow) {
107-
if (windowManager != null) {
108-
windowManager.removeView(flutterView);
109-
windowManager = null;
110-
flutterView.detachFromFlutterEngine();
111-
stopSelf();
112-
}
113-
isRunning = false;
109+
stopSelf();
114110
return START_STICKY;
115111
}
116-
if (windowManager != null) {
112+
if(windowManager != null && flutterView != null) {
117113
windowManager.removeView(flutterView);
118114
windowManager = null;
115+
}
116+
if(flutterView != null) {
119117
flutterView.detachFromFlutterEngine();
120-
stopSelf();
118+
flutterView = null;
121119
}
122120
isRunning = true;
123121
Log.d("onStartCommand", "Service started");
@@ -147,7 +145,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
147145

148146
BasicMessageChannel<Object> overlayMessageChannel = new BasicMessageChannel<>(FlutterEngineCache.getInstance().get(OverlayConstants.CACHED_TAG).getDartExecutor().getBinaryMessenger(), OverlayConstants.MESSENGER_TAG, JSONMessageCodec.INSTANCE);
149147
overlayMessageChannel.setMessageHandler((message, reply) -> {
150-
if(CachedMessageChannels.mainAppMessageChannel == null) {
148+
if (CachedMessageChannels.mainAppMessageChannel == null) {
151149
reply.reply(false);
152150
return;
153151
}

0 commit comments

Comments
 (0)