You can use the cancel() method of Toast to close the Toast display.
Use a variable to keep a link to each Toast while you show it, and just call cancel() before showing the other.
private Toast mToast = null;
You can even wrap this in a small class:
public class SingleToast { private static Toast mToast; public static void show(Context context, String text, int duration) { if (mToast != null) mToast.cancel(); mToast = Toast.makeText(context, text, duration); mToast.show(); } }
and use it in your code as follows:
SingleToast.show(this, "Hello World", Toast.LENGTH_LONG);
//
source share