How to stop displaying message from Toast when Application is closed?

前端 未结 5 1356
自闭症患者
自闭症患者 2020-12-05 20:26

This is my sample code:

public class MainActivity extends Activity {

    Button buttonClick;
    @Override
    protected void onCreate(Bundle savedInstanceS         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 20:46

    Try this,

    You can cancel Toast showing using this code.

      final Toast toast = Toast.makeText(getApplicationContext(), "This message will    disappear     in half second", Toast.LENGTH_SHORT);
    toast.show();
    
    Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
           @Override
           public void run() {
               toast.cancel(); 
           }
    }, 500);
    

提交回复
热议问题