pull/32/head
kunfei 5 years ago
parent 198ea81c96
commit dd91e54e38
  1. 32
      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<WebService>()
}
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)
}
}
Loading…
Cancel
Save