From e7e48e1a65fdaa361e14e7e77e24043a63126bd6 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期二, 13 一月 2026 15:52:15 +0800
Subject: [PATCH] 2026年01月13日15:47:59 升级gradle版本

---
 app/src/main/java/com/hdl/photovoltaic/uni/MyForegroundService.java |   61 +++++++++++++++++++++++-------
 1 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/uni/MyForegroundService.java b/app/src/main/java/com/hdl/photovoltaic/uni/MyForegroundService.java
index e010d83..561110b 100644
--- a/app/src/main/java/com/hdl/photovoltaic/uni/MyForegroundService.java
+++ b/app/src/main/java/com/hdl/photovoltaic/uni/MyForegroundService.java
@@ -1,18 +1,22 @@
 package com.hdl.photovoltaic.uni;
 
+import android.app.ActivityManager;
 import android.app.Notification;
 import android.app.NotificationChannel;
 import android.app.NotificationManager;
 import android.app.Service;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Build;
 import android.os.IBinder;
+import android.util.Log;
 
 import androidx.annotation.Nullable;
 import androidx.core.app.NotificationCompat;
 
 import com.hdl.photovoltaic.R;
 
+import java.util.List;
 
 
 public class MyForegroundService extends Service {
@@ -29,21 +33,17 @@
         isRunning = true;
 
     }
-//    @Override
-//    public void onTaskRemoved(Intent rootIntent) {
-//        super.onTaskRemoved(rootIntent);
-//        isRunning = false;
-
-    /// /        // 鍋滄鍓嶅彴鐘舵�侊紝绉婚櫎閫氱煡
-    /// /        stopForeground(true);  // true琛ㄧず绉婚櫎閫氱煡
-    /// ///        // 鍋滄鏈嶅姟
-    /// ///        stopSelf();
-//        // 1. 鍏堢Щ闄ゅ墠鍙扮姸鎬侊紙鍙�夛紝浣嗗缓璁級
-//        stopForeground(true);
-//
-//        // 2. 鍋滄鏈嶅姟
-//        stopSelf();
-//    }
+    @Override
+    public void onTaskRemoved(Intent rootIntent) {
+        super.onTaskRemoved(rootIntent);
+        // 褰撳簲鐢ㄤ粠鏈�杩戜换鍔′腑绉婚櫎鏃惰皟鐢�
+        stopForeground(true);
+        stopSelf();
+        killAppProcess(this);
+//        // 3. 缁撴潫杩涚▼
+//        android.os.Process.killProcess(android.os.Process.myPid());
+//        System.exit(0);
+    }
     @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
         // 鍒涘缓閫氱煡
@@ -88,10 +88,41 @@
     public void onDestroy() {
         super.onDestroy();
         isRunning = false;
+        // 娓呯悊璧勬簮
+        stopForeground(true);
     }
 
     public static boolean isServiceRunning() {
         return isRunning;
     }
+
+    /**
+     * 鍏虫帀app鎵�鏈夎繘绋�
+     *
+     * @param context 涓婁笅鏂�
+     */
+    private void killAppProcess(Context context) {
+//        AppManagerUtils.getAppManager().finishAllActivity();
+//        Log.d("===6666666","");
+        try {
+            android.app.ActivityManager manager = (android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+            List<ActivityManager.RunningAppProcessInfo> processInfos = manager.getRunningAppProcesses();
+            // 鍏堟潃鎺夌浉鍏宠繘绋嬶紝鏈�鍚庡啀鏉�鎺変富杩涚▼
+            for (android.app.ActivityManager.RunningAppProcessInfo runningAppProcessInfo : processInfos) {
+                if ((runningAppProcessInfo.uid == android.os.Process.myUid()) && (runningAppProcessInfo.pid != android.os.Process.myPid())) {
+                    try {
+                        android.os.Process.killProcess(runningAppProcessInfo.pid);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+
+            android.os.Process.killProcess(android.os.Process.myPid());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        System.exit(0);
+    }
 }
 

--
Gitblit v1.8.0