title: how to stop display toast before the app close/keyboard open (without overlapping the keyboard layout and the home page)
body: <p>Just to clarify what I am asking: I am already closing the toast when call OnStop()/OnPause()/Edit Text OnClick(). Despite the title looks like, this isn't a duplicate of: <a href="https://stackoverflow.com/questions/14806651/how-to-stop-displaying-message-from-toast-when-application-is-closed">How to stop displaying message from Toast when Application is closed?</a> (sorry, I couldn't found I better title)</p>
  
  <p>So I'm not asking how to close the toast, but how can I update the toast closed before finish the app.</p>
  
  <p>Just to give an example, the alarm clock native of my nexus 5 (4.4.4) shows a notification when you delete an alarm setted. If when close/minimize the app, it close the toast, then close/minimize the app. I would know a code that allow me to do like that.</p>
  
  <p>This is my sample code:</p>
  
  <pre><code>public class MainActivity extends Activity {
          private Toast toast;
          private Button buttonClick;
          private EditText editTextClick;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
  
              buttonClick = (Button) findViewById(R.id.buttonClick);
              editTextClick = (EditText) findViewById(R.id.editTextClick);
  
              buttonClick.setOnClickListener(new OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
                      if (toast != null) {
                          toast.cancel();
                      }
                      toast = Toast.makeText(this, "This might close before the app stop", Toast.LENGTH_SHORT);
                      toast.show();
                  }
              });
  
  
               editTextClick.setOnClickListener(new OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
                      toast = Toast.makeText(this, "This might close before the keyboard open", Toast.LENGTH_SHORT);
                      toast.show();
                      if (toast != null) {
                           toast.cancel();
                      }
                  }
              });
  
          }
  
          @Override
          protected void onStop() {
              // TODO Auto-generated method stub
              if (toast != null) {
                  toast.cancel();
              }
  
              super.onStop();
          }
  
          @Override
          protected void onPause() {
              // TODO Auto-generated method stub
              if (toast != null) {
                  toast.cancel();      // This close toast when stop called 
              }
              super.onPause();
          }
  
      }
  </code></pre>
  
  <p>I am trying to close a the toast notification ever time the edit text is clicked. But it first open the keyboard (overlapping the toast and keyboard for a while) than close the toast.</p>
  
  <p>The same happen when I close the app or alternate app. The toast disappear after overlapping the other layout.</p>
  
  <p>I have already try to use a <code>Thread.sleep(1000);</code> (within a try-catch clause) and after <code>if(toast != null) { toast.cancel(); }</code>, but doesn't change anything.</p>
  
  <p>What I could do in this sample code to make it closes the toast then do others things (like open the keyboard, close the app, show recent apps, etc).</p>