Search code examples
androidtoast

How to stop showing Toast messages which are in queue in android


Below code shows my present implementation , here am creating a toast object and closing in onPause(). This works fine until there is no queue for toasts.

public static long **savedTimeStamp=0**;
    Toast showToastMessage;

if(System.currentTimeMillis()/1000 - savedTimeStamp >= 60 || savedTimeStamp==0){
    showToastMessage=Toast.makeText(this.this, "Toast message", Toast.LENGTH_LONG);
    showToastMessage.show();
    savedTimeStamp=System.currentTimeMillis()/1000;
}

    @Override
             protected void onPause() {
                  super.onPause();
                  if(showToastMessage!=null)
                    {
                    showToastMessage.cancel();
                    }
    }

Solution

  • Final conclusion is: Toast in Que cannot be stoped . So avoid using toast in que.