I have a problem with my app that if the user clicks the button multiple times quickly, then multiple events are generated before even my dialog holding the button disappear
My solution, need to call removeall
when we exit (destroy) from the fragment and activity:
import android.os.Handler
import android.os.Looper
import java.util.concurrent.TimeUnit
//single click handler
object ClickHandler {
//used to post messages and runnable objects
private val mHandler = Handler(Looper.getMainLooper())
//default delay is 250 millis
@Synchronized
fun handle(runnable: Runnable, delay: Long = TimeUnit.MILLISECONDS.toMillis(250)) {
removeAll()//remove all before placing event so that only one event will execute at a time
mHandler.postDelayed(runnable, delay)
}
@Synchronized
fun removeAll() {
mHandler.removeCallbacksAndMessages(null)
}
}