diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 99334fd1c..3dcefd09d 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -1,12 +1,44 @@ package io.legado.app.service +import android.content.Context +import android.content.Intent import io.legado.app.base.BaseService +import io.legado.app.constant.Action +import org.jetbrains.anko.startService class WebService : BaseService() { + companion object { + var isRun = false + + fun start(context: Context) { + context.startService() + } + + fun stop(context: Context) { + if (isRun) { + val intent = Intent(context, WebService::class.java) + intent.action = Action.stop + context.startService(intent) + } + } + + } override fun onCreate() { super.onCreate() + isRun = true } + override fun onDestroy() { + super.onDestroy() + isRun = false + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + when (intent?.action) { + Action.stop -> stopSelf() + } + return super.onStartCommand(intent, flags, startId) + } } \ No newline at end of file