Android – Hide all shown Toast Messages

My solution was to initialize a single Toast in the activity. Then changing its text on each click.

Toast mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
if (a) {
  mToast.setText("This is a");
  mToast.show();
} else if (b) {
  mToast.setText("This is b");
  mToast.show();
}

Leave a Comment