There's an answer for setTimeout https://stackoverflow.com/a/18381353/433570
It doesn't provide info whether we can cancel the timer as we could in javascript.
Is there a timer that is cancellable in android?
According to the documentation of Handler
public final void removeCallbacks (Runnable r)
Added in API level 1
Remove any pending posts of Runnable r that are in the message queue.
Example code:
Runnable runnable = new Runnable() {
public void run() {
Log.i("Tag", "Runnable running!");
}
};
Handler handler = new android.os.Handler();
handler.postDelayed(runnable, 1000);
handler.removeCallbacks(runnable);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With