@@ -76,6 +76,12 @@ 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 ) {
80+ windowManager .removeView (flutterView );
81+ windowManager = null ;
82+ }
83+ flutterView .detachFromFlutterEngine ();
84+ flutterView = null ;
7985 NotificationManager notificationManager = (NotificationManager ) getApplicationContext ().getSystemService (Context .NOTIFICATION_SERVICE );
8086 notificationManager .cancel (OverlayConstants .NOTIFICATION_ID );
8187 if (CachedMessageChannels .overlayMessageChannel != null ){
@@ -89,21 +95,9 @@ public void onDestroy() {
8995 public int onStartCommand (Intent intent , int flags , int startId ) {
9096 mResources = getApplicationContext ().getResources ();
9197 boolean isCloseWindow = intent .getBooleanExtra (INTENT_EXTRA_IS_CLOSE_WINDOW , false );
92- if (isCloseWindow ) {
93- if (windowManager != null ) {
94- windowManager .removeView (flutterView );
95- windowManager = null ;
96- flutterView .detachFromFlutterEngine ();
97- stopSelf ();
98- }
99- isRunning = false ;
100- return START_STICKY ;
101- }
102- if (windowManager != null ) {
103- windowManager .removeView (flutterView );
104- windowManager = null ;
105- flutterView .detachFromFlutterEngine ();
98+ if (isCloseWindow || windowManager != null ) {
10699 stopSelf ();
100+ return START_STICKY ;
107101 }
108102 isRunning = true ;
109103 Log .d ("onStartCommand" , "Service started" );
@@ -128,7 +122,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
128122
129123 BasicMessageChannel <Object > overlayMessageChannel = new BasicMessageChannel <>(FlutterEngineCache .getInstance ().get (OverlayConstants .CACHED_TAG ).getDartExecutor ().getBinaryMessenger (), OverlayConstants .MESSENGER_TAG , JSONMessageCodec .INSTANCE );
130124 overlayMessageChannel .setMessageHandler ((message , reply ) -> {
131- if (CachedMessageChannels .mainAppMessageChannel == null ) {
125+ if (CachedMessageChannels .mainAppMessageChannel == null ) {
132126 reply .reply (false );
133127 return ;
134128 }
0 commit comments