I am confused about how to use Toast to print out messages. I need to use it to print out messages that come from the thread's while loop. 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:
myActivity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(context, text, duration).show();
}
});
来源:https://stackoverflow.com/questions/15057631/android-toast-message-from-a-separate-thread-class