Skip to content

Instantly share code, notes, and snippets.

@tkuenneth
Created October 15, 2019 13:50
Show Gist options
  • Save tkuenneth/3e4111e47f94f80381c903a371b23229 to your computer and use it in GitHub Desktop.
Save tkuenneth/3e4111e47f94f80381c903a371b23229 to your computer and use it in GitHub Desktop.
How to use CountDownTimer
package com.thomaskuenneth.playground
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.CountDownTimer
import android.util.Log
class CountDownTimerDemo : AppCompatActivity() {
private val tag = CountDownTimerDemo::class.simpleName
private val cdt = object : CountDownTimer(7000, 1000) {
override fun onTick(millisUntilFinished: Long) {
Log.d(tag, "seconds remaining: " + millisUntilFinished / 1000)
}
override fun onFinish() {
Log.d(tag, "done")
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
cdt.start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment