Browse Source

1.登陆后,锁定平板时需要杀掉其他应用进程。

20241218TB223FC(测试jar包)
wangwanlei 9 months ago
parent
commit
2f45aeadd0

+ 2
- 17
app/src/main/java/com/xhly/manageapp/AppAdapter.kt View File

40
         holder.mBinding.itemCv.setText(appInfo.name)
40
         holder.mBinding.itemCv.setText(appInfo.name)
41
         holder.mBinding.itemCv.setOnClickListener {
41
         holder.mBinding.itemCv.setOnClickListener {
42
             if (appInfo.packageName.equals(Const.CUSTOMSPEEDAPP)){
42
             if (appInfo.packageName.equals(Const.CUSTOMSPEEDAPP)){
43
-                clearMemory()
43
+                StrategyUtils.clearMemory(context,data)
44
+                Toaster.show("加速完成。")
44
             }else if (appInfo.packageName.equals(Const.CUSTOMCLEARAPP)){
45
             }else if (appInfo.packageName.equals(Const.CUSTOMCLEARAPP)){
45
                 Toaster.showLong("清理缓存")
46
                 Toaster.showLong("清理缓存")
46
             }else if (appInfo.packageName.equals(Const.CUSTOMROTATIONAPP)){
47
             }else if (appInfo.packageName.equals(Const.CUSTOMROTATIONAPP)){
64
         }
65
         }
65
     }
66
     }
66
 
67
 
67
-    private fun clearMemory() {
68
-        try {
69
-            val service : ActivityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
70
-            val runningAppProcesses = service.runningAppProcesses
71
-            runningAppProcesses.forEach {process->
72
-                LogShow("当前运行应用名称"+process.processName+"|||"+process?.importanceReasonComponent?.packageName)
73
-                data.filter { it.packageName.equals(process.processName) }.forEach {
74
-                    ManageApplication.killApplicationProcess(it.packageName)
75
-                }
76
-            }
77
-            Toaster.show("加速完成。")
78
-        }catch (e:Exception){
79
-
80
-        }
81
-    }
82
-
83
     class AppViewHolder(binding: ItemAppBinding) : RecyclerView.ViewHolder(binding.root) {
68
     class AppViewHolder(binding: ItemAppBinding) : RecyclerView.ViewHolder(binding.root) {
84
         var mBinding = binding
69
         var mBinding = binding
85
     }
70
     }

+ 5
- 1
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt View File

451
             }
451
             }
452
 
452
 
453
             Const.CODE2002.toString() -> {
453
             Const.CODE2002.toString() -> {
454
+                //杀掉其他app之保留自己
455
+                val appList = AppUtils.GetAppList(this)
456
+                StrategyUtils.clearMemory(this, appList)
454
                 spUtils.setParam(Const.DISABLEPAD, true)
457
                 spUtils.setParam(Const.DISABLEPAD, true)
455
-                useTimeStrategy()
458
+                //useTimeStrategy()
459
+                startIntentActivity(MainActivity().javaClass)
456
             }
460
             }
457
 
461
 
458
             Const.CODE2003.toString() -> {
462
             Const.CODE2003.toString() -> {

+ 19
- 0
app/src/main/java/com/xhly/manageapp/utils/StrategyUtils.kt View File

1
 package com.xhly.manageapp.utils
1
 package com.xhly.manageapp.utils
2
 
2
 
3
+import android.app.ActivityManager
3
 import android.content.Context
4
 import android.content.Context
4
 import com.google.gson.reflect.TypeToken
5
 import com.google.gson.reflect.TypeToken
5
 import com.xhly.corelib.Const
6
 import com.xhly.corelib.Const
290
     public fun setNetWhiteList(data:ArrayList<String>){
291
     public fun setNetWhiteList(data:ArrayList<String>){
291
         ManageApplication.setUrlWhiteListWrite(data)
292
         ManageApplication.setUrlWhiteListWrite(data)
292
     }
293
     }
294
+    /**
295
+     * 清理其他app
296
+     */
297
+    public fun clearMemory(context: Context,data: List<AppInfo>) {
298
+        try {
299
+            val service : ActivityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
300
+            val runningAppProcesses = service.runningAppProcesses
301
+            runningAppProcesses.forEach {process->
302
+                LogShow("当前运行应用名称"+process.processName+"|||"+process?.importanceReasonComponent?.packageName)
303
+                data.filter { it.packageName.equals(process.processName) }.forEach {
304
+                    LogShow("当前运行应用名称,被清理的时"+it.packageName)
305
+                    ManageApplication.killApplicationProcess(it.packageName)
306
+                }
307
+            }
308
+        }catch (e:Exception){
309
+
310
+        }
311
+    }
293
 }
312
 }

Loading…
Cancel
Save