Can I cancel previous Toast when I want to show an other Toast?

You just need to declare a “Toast” var like this:

Toast toastMessage;

Then in your function, do it like this:

if (toastMessage!= null) {
    toastMessage.cancel();
}
toastMessage= Toast.makeText(context, "The message you want to display", duration);
toastMessage.show();

Leave a Comment