Skip to content

Commit

Permalink
Fix potential crashes when creating foreground service
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Jan 21, 2019
1 parent 00410a8 commit 3acf090
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Build
import android.os.IBinder
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -66,7 +67,11 @@ class BackendServiceConnection : ServiceConnection, DefaultLifecycleObserver {
}

fun start(intent: Intent = QuasselService.intent(context!!)) {
context?.startService(intent)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context?.startForegroundService(intent)
} else {
context?.startService(intent)
}
}

@Synchronized
Expand Down

0 comments on commit 3acf090

Please sign in to comment.