Skip to content

Instantly share code, notes, and snippets.

@bholota
Created December 31, 2018 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bholota/33ecd95c5ab3e5f43b34c4aa29f1d775 to your computer and use it in GitHub Desktop.
Save bholota/33ecd95c5ab3e5f43b34c4aa29f1d775 to your computer and use it in GitHub Desktop.
class SampleService : Service() {
companion object {
private val LAUNCHER = ForegroundServiceLauncher(SampleService::class.java)
@JvmStatic
fun start(context: Context) = LAUNCHER.startService(context)
@JvmStatic
fun stop(context: Context) = LAUNCHER.stopService(context)
}
override fun onCreate() {
super.onCreate()
startForeground(ID, notification)
//...
LAUNCHER.onServiceCreated(this)
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
//...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment