Skip to content

Instantly share code, notes, and snippets.

@thesiamak
Created August 19, 2021 09:26
Show Gist options
  • Save thesiamak/7a4732b178db9aa35e0bcea767e72541 to your computer and use it in GitHub Desktop.
Save thesiamak/7a4732b178db9aa35e0bcea767e72541 to your computer and use it in GitHub Desktop.
class DisplayTimer (context: Context) : LinearLayout(context)
, LifecycleObserver {
private var timer:Timer? =null
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun igniteTimer(){
timer = Timer("ring the bell").apply{
schedule(object : TimerTask() {
override fun run() {
Tick()
}
},200_000, 250)
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
private fun release(){
timer?.cancel()
timer?.purge()
}
private fun Tick() {
// update the countdown timer view here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment