I have seen a number of questions on cancelling toast. None of them is working.
I have a custom Toast. The code for that is all but one line same as http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView
The difference is as follows.
In the start of this method, I have added the following line to cancel the toast.
if (toast!=null){
toast.cancel();
}
The method is called when user selects (onClick) the view/layout. The issue is when the user selects few times, the toast will get queued up (the toast.cancel is not working).
Any solutions?
[update] I tried making toast object a static variable. Still dont work.
I suffered from same issue (custom toast queuing up) and found a solution. It worked fine in my case.
Having custom toast object initially set to null
.
If this is null, create new custom toast object with "new".
As far as you are in same activity, don't "new" to create new object. Instead, use that object. Since setText()
won't work in this case, use setView()
as you do with your custom toast.
With this way show(), cancel(), show(), cancel()
worked exactly as I expect. No delay, no queuing.
Hope this helps.
In the end, I created a Custom Dialog so that the user is blocked from doing anything else (and avoids multiple toasts popping up). Added a onClick Listener Event to close the dialog when user clicks the same.
Sad that Toast.cancel() doesn't work.
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