@@ -76,6 +76,12 @@ public IBinder onBind(Intent intent) {
76
76
public void onDestroy () {
77
77
Log .d ("OverLay" , "Destroying the overlay window service" );
78
78
isRunning = false ;
79
+ if (windowManager != null ) {
80
+ windowManager .removeView (flutterView );
81
+ windowManager = null ;
82
+ }
83
+ flutterView .detachFromFlutterEngine ();
84
+ flutterView = null ;
79
85
NotificationManager notificationManager = (NotificationManager ) getApplicationContext ().getSystemService (Context .NOTIFICATION_SERVICE );
80
86
notificationManager .cancel (OverlayConstants .NOTIFICATION_ID );
81
87
if (CachedMessageChannels .overlayMessageChannel != null ){
@@ -89,21 +95,9 @@ public void onDestroy() {
89
95
public int onStartCommand (Intent intent , int flags , int startId ) {
90
96
mResources = getApplicationContext ().getResources ();
91
97
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 ) {
106
99
stopSelf ();
100
+ return START_STICKY ;
107
101
}
108
102
isRunning = true ;
109
103
Log .d ("onStartCommand" , "Service started" );
@@ -128,7 +122,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
128
122
129
123
BasicMessageChannel <Object > overlayMessageChannel = new BasicMessageChannel <>(FlutterEngineCache .getInstance ().get (OverlayConstants .CACHED_TAG ).getDartExecutor ().getBinaryMessenger (), OverlayConstants .MESSENGER_TAG , JSONMessageCodec .INSTANCE );
130
124
overlayMessageChannel .setMessageHandler ((message , reply ) -> {
131
- if (CachedMessageChannels .mainAppMessageChannel == null ) {
125
+ if (CachedMessageChannels .mainAppMessageChannel == null ) {
132
126
reply .reply (false );
133
127
return ;
134
128
}
0 commit comments