Browse Source

1.打开应用商店时取消当前安装任务

20241218TB223FC(测试jar包)
wangwanlei 10 months ago
parent
commit
23e168cd83

+ 8
- 0
app/src/main/java/com/xhly/manageapp/AppAdapter.kt View File

@@ -15,6 +15,7 @@ import com.xhly.corelib.bean.AppInfo
15 15
 import com.xhly.corelib.eventbus.UIEvent
16 16
 import com.xhly.corelib.utils.LogShow
17 17
 import com.xhly.corelib.utils.SystemUtil
18
+import com.xhly.manageapp.utils.InstallUtils
18 19
 import com.xhly.manageapp.utils.StrategyUtils
19 20
 import java.util.Calendar
20 21
 
@@ -64,6 +65,7 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
64 65
                 context.startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
65 66
             }else if (appInfo.packageName.equals(Const.STOREAPPPKG)){
66 67
                 //跳转应用商店
68
+                var destroyFlag=false
67 69
                 try {
68 70
                     val launchIntent = Intent()
69 71
                     launchIntent.setComponent(
@@ -73,8 +75,14 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
73 75
                         )
74 76
                     )
75 77
                     context.startActivity(launchIntent)
78
+                    destroyFlag=true
76 79
                 }catch (e:Exception){
80
+                    destroyFlag=false
77 81
                     Toaster.showLong("失败原因"+e.toString())
82
+                }finally {
83
+                    if (destroyFlag){
84
+                        InstallUtils.destroyInstallUtils()
85
+                    }
78 86
                 }
79 87
             } else{
80 88
                 try {

+ 3
- 3
app/src/main/java/com/xhly/manageapp/utils/InstallUtils.kt View File

@@ -51,10 +51,9 @@ object InstallUtils {
51 51
         if (isRunning) {
52 52
             return
53 53
         }
54
-        /*if (coroutineScope==null){
54
+        if (coroutineScope==null){
55 55
             coroutineScope=CoroutineScope(Dispatchers.IO)
56
-        }*/
57
-        coroutineScope=CoroutineScope(Dispatchers.IO)
56
+        }
58 57
         coroutineScope?.launch {
59 58
             while (queue.size > 0) {
60 59
                 isRunning = true
@@ -80,6 +79,7 @@ object InstallUtils {
80 79
         isRunning= false
81 80
         isInstalling = false
82 81
         coroutineScope?.cancel()
82
+        LogShow("任务取消")
83 83
     }
84 84
 }
85 85
 

Loading…
Cancel
Save