From dd91e54e384066d2854d38cd3c66ca9f4e5c8446 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 1 Sep 2019 20:58:20 +0800 Subject: [PATCH] up --- .../java/io/legado/app/service/WebService.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) 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