Skip to content

Instantly share code, notes, and snippets.

@molidev8
Created June 11, 2022 17:07
Show Gist options
  • Save molidev8/6e5bbc077f8394316b444c97fb374118 to your computer and use it in GitHub Desktop.
Save molidev8/6e5bbc077f8394316b444c97fb374118 to your computer and use it in GitHub Desktop.
A foreground service intialization
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
startService(Intent(this, TimerService::class.java))
bindService(
Intent(this, TimerService::class.java),
timerServiceConnection,
Context.BIND_AUTO_CREATE
)
setContent {
// Some Jetpack Compose UI
}
}
override fun onDestroy() {
super.onDestroy()
if (isTimerServiceBound) {
unbindService(timerServiceConnection)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment