Horis hace 2 años
padre
commit
087aefa826
Se han modificado 1 ficheros con 5 adiciones y 1 borrados
  1. 5 1
      app/src/main/java/io/legado/app/base/BaseService.kt

+ 5 - 1
app/src/main/java/io/legado/app/base/BaseService.kt

@@ -21,6 +21,7 @@ import kotlin.coroutines.CoroutineContext
 abstract class BaseService : LifecycleService() {
 
     private val simpleName = this::class.simpleName.toString()
+    private var isForeground = false
 
     fun <T> execute(
         scope: CoroutineScope = lifecycleScope,
@@ -42,7 +43,10 @@ abstract class BaseService : LifecycleService() {
         LogUtils.d(simpleName) {
             "onStartCommand $intent ${intent?.toUri(0)}"
         }
-        startForegroundNotification()
+        if (!isForeground) {
+            startForegroundNotification()
+            isForeground = true
+        }
         return super.onStartCommand(intent, flags, startId)
     }