Skip to content

Instantly share code, notes, and snippets.

@ziginsider
Created July 9, 2021 22:14
Show Gist options
  • Save ziginsider/daa5f67626bb59238009d054934981cd to your computer and use it in GitHub Desktop.
Save ziginsider/daa5f67626bb59238009d054934981cd to your computer and use it in GitHub Desktop.
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun onAppBackgrounded() {
val startIntent = Intent(this, ForegroundService::class.java)
startIntent.putExtra(COMMAND_ID, COMMAND_START)
startIntent.putExtra(STARTED_TIMER_TIME_MS, startTime)
startService(startIntent)
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onAppForegrounded() {
val stopIntent = Intent(this, ForegroundService::class.java)
stopIntent.putExtra(COMMAND_ID, COMMAND_STOP)
startService(stopIntent)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment