Просмотр исходного кода

feat: 朗读之偶然崩溃问题

HapeLee 1 месяц назад
Родитель
Сommit
bfa55b6a24
1 измененных файлов с 4 добавлено и 3 удалено
  1. 4 3
      app/src/main/java/io/legado/app/model/ReadAloud.kt

+ 4 - 3
app/src/main/java/io/legado/app/model/ReadAloud.kt

@@ -175,9 +175,10 @@ object ReadAloud {
 
     fun stop(context: Context) {
         if (BaseReadAloudService.requestStop()) {
-            val intent = Intent(context, aloudClass)
-            intent.action = IntentAction.stop
-            context.startForegroundServiceCompat(intent)
+            // Stopping an already-running service must not issue a new foreground-start request.
+            // If its last start is still pending, the stop action could otherwise finish the
+            // service without ever calling startForeground(), crashing the process on timeout.
+            context.stopService(Intent(context, aloudClass))
         }
     }