简体   繁体   English

来自单独线程类的Android toast消息

[英]Android toast message from a separate thread class

I am confused about how to use Toast to print out messages. 我对如何使用Toast打印消息感到困惑。 I need to use it to print out messages that come from the thread's while loop. 我需要用它来打印来自线程while循环的消息。 My thread which renders graphics are on a different class than my activity. 我呈现图形的线程与我的活动不同。 I mean, they are not implemented in the same file. 我的意思是,它们没有在同一个文件中实现。 Is there a way to do this? 有没有办法做到这一点?

You can use runOnUiThread : 您可以使用runOnUiThread

myActivity.runOnUiThread(new Runnable() {

 public void run() {
    Toast.makeText(context, text, duration).show();
 }

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM