How to use toast message inside Thread in Android

后端 未结 7 1156
故里飘歌
故里飘歌 2020-12-20 00:19

I am facing some problems when I\'m using Toast inside run method of Thread class.

My error Logcat

09-16 11:42:38.140: E/AndroidRuntime(1446): in wri         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-20 00:34

    You may display your Toast message as below:

    YourActivityName.this.runOnUiThread(new Runnable() {
    
            @Override
            public void run() {
                Toast.makeText(YourActivityName.this, "This is Toast!!!", Toast.LENGTH_SHORT).show();
    
            }
        });
    

提交回复
热议问题