Преглед изворни кода

修复退出应用时,悬浮窗仍然存在的bug

zengjiebin пре 7 година
родитељ
комит
7041d81b61

+ 0 - 4
app/src/main/java/com/kfzs/duanduan/KFZSApp.java

@@ -100,10 +100,6 @@ public class KFZSApp extends MultiDexApplication {
     public void quit() {
         try {
             Aria.download(this).stopAllTask();
-            stopService(new Intent(this, DownloadService.class));
-            stopService(new Intent(this, FloatService.class));
-            if(DataUtil.IS_USE_SCREEN_SHOT)
-                stopService(new Intent(this, FloatShotScreenService.class));
             ActivityManager.getInstance().finishAllActivity();
         } catch (Exception e) {
             Log.e(TAG, "quit error" + e.getMessage() + "\n" + e.getCause());

+ 13 - 2
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -2,6 +2,7 @@ package com.sheep.jiuyan.samllsheep;
 
 import android.app.Activity;
 import android.content.Context;
+import android.content.Intent;
 import android.os.Bundle;
 import android.support.multidex.MultiDex;
 
@@ -16,6 +17,7 @@ import com.sheep.gamegroup.util.ActivityManager;
 import com.sheep.gamegroup.util.AppUtil;
 import com.sheep.gamegroup.util.ChannelContent;
 import com.sheep.gamegroup.util.ConnectAddress;
+import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.SysAppUtil;
@@ -23,6 +25,9 @@ import com.sheep.gamegroup.util.UMConfigUtils;
 import com.sheep.gamegroup.view.activity.LoginAct;
 import com.sheep.gamegroup.view.activity.PhoneAct;
 import com.sheep.gamegroup.view.activity.SplashAct;
+import com.sheep.jiuyan.samllsheep.service.DownloadService;
+import com.sheep.jiuyan.samllsheep.service.FloatService;
+import com.sheep.jiuyan.samllsheep.service.FloatShotScreenService;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 import com.tencent.bugly.Bugly;
@@ -159,7 +164,8 @@ public class SheepApp extends BaseApplication {
                     LogUtil.println("SheepApp onActivityStarted", mActivityCount);
                     UMConfigUtils.Event.SHEEP_STARTED.onEvent();
                     Jump2View.getInstance().startFloat(activity, false);
-                    Jump2View.getInstance().startShotScreenFloat(activity, false);
+                    if(DataUtil.IS_USE_SCREEN_SHOT)
+                        Jump2View.getInstance().startShotScreenFloat(activity, false);
                 }
             }
         }
@@ -182,7 +188,8 @@ public class SheepApp extends BaseApplication {
                     LogUtil.println("SheepApp onActivityStopped", mActivityCount);
                     UMConfigUtils.Event.SHEEP_STOPPED.onEvent();
                     Jump2View.getInstance().startFloat(activity, true);
-                    Jump2View.getInstance().startShotScreenFloat(activity, true);
+                    if(DataUtil.IS_USE_SCREEN_SHOT)
+                        Jump2View.getInstance().startShotScreenFloat(activity, true);
                 }
             }
         }
@@ -195,6 +202,10 @@ public class SheepApp extends BaseApplication {
         public void onActivityDestroyed(Activity activity) {
             if(mActivityCount == 0) {
                 LogUtil.println("SheepApp onActivityDestroyed", mActivityCount);
+                stopService(new Intent(SheepApp.this, DownloadService.class));
+                stopService(new Intent(SheepApp.this, FloatService.class));
+                if(DataUtil.IS_USE_SCREEN_SHOT)
+                    stopService(new Intent(SheepApp.this, FloatShotScreenService.class));
                 UMConfigUtils.Event.SHEEP_DESTROYED.onEvent();
             }
         }

+ 3 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/service/FloatService.java

@@ -150,9 +150,11 @@ public class FloatService extends Service {
     @Override
     public void onDestroy() {
         super.onDestroy();
+        removeMessages();
         if (floatView != null) {
             try {
-                wm.removeViewImmediate(floatView);
+                if(isAdded)
+                    wm.removeViewImmediate(floatView);
             } catch (Exception e) {
                 e.printStackTrace();
             }

+ 4 - 2
app/src/main/java/com/sheep/jiuyan/samllsheep/service/FloatShotScreenService.java

@@ -1,4 +1,4 @@
-package com.sheep.jiuyan.samllsheep.service;
+    package com.sheep.jiuyan.samllsheep.service;
 
 import android.annotation.TargetApi;
 import android.app.Activity;
@@ -69,9 +69,11 @@ public class FloatShotScreenService extends Service {
     @Override
     public void onDestroy() {
         super.onDestroy();
+        removeMessages();
         if (floatView != null) {
             try {
-                wm.removeViewImmediate(floatView);
+                if(isAdded)
+                    wm.removeViewImmediate(floatView);
             } catch (Exception e) {
                 e.printStackTrace();
             }