Use ContextCompat.startForegroundService in startTimerService

The compat one has the logic method has, let's use that instead.
This commit is contained in:
Ebrahim Byagowi 2021-12-04 21:29:04 +03:30
parent b47b3854ed
commit 62cb24f5d6

View File

@ -9,8 +9,8 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.os.IBinder import android.os.IBinder
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import com.simplemobiletools.clock.R import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.extensions.getFormattedDuration import com.simplemobiletools.clock.extensions.getFormattedDuration
import com.simplemobiletools.clock.extensions.getOpenTimerTabIntent import com.simplemobiletools.clock.extensions.getOpenTimerTabIntent
@ -118,13 +118,8 @@ class TimerService : Service() {
} }
} }
@RequiresApi(Build.VERSION_CODES.O)
fun startTimerService(context: Context) { fun startTimerService(context: Context) {
if (isOreoPlus()) { ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java))
context.startForegroundService(Intent(context, TimerService::class.java))
} else {
context.startService(Intent(context, TimerService::class.java))
}
} }
object TimerStopService object TimerStopService