How to use toast message inside Thread in Android

后端 未结 7 1139
故里飘歌
故里飘歌 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:48

    You can not print Toast in Thread, because Thread is running in background and it will not affect GUI things. You have to do it using UI Thread.

    runOnUiThread(new Runnable() {
          @Override
              public void run() {
                 Toast.makeText(this, "YOUR MESSAGE TO PRINT", Toast.LENGTH_LONG).show().
              }
       });
    
    0 讨论(0)
提交回复
热议问题