I am using handler.postDelayed()
to create a waiting period before the next stage of my app takes place. During the wait period I am displaying a dialog with progress bar and cancel button.
My problem is I can't find a way to cancel the postDelayed task before the time elapses.
Here is a class providing a cancel method for a delayed action
I do this to post a delayed runnable:
And this to remove it:
myHandler.removeCallbacks(myRunnable);
It worked for me when I called CancelCallBacks(this) inside the post delayed runnable by handing it via a boolean
Hope this gist help https://gist.github.com/imammubin/a587192982ff8db221da14d094df6fb4
MainActivity as Screen Launcher with handler & runnable function, the Runnable run to login page or feed page with base preference login user with firebase.
Another way is to handle the Runnable itself:
In case you do have multiple inner/anonymous runnables passed to same handler, and you want to cancel all at same event use
handler.removeCallbacksAndMessages(null);