i want to post some message with setText() method inside thread when readline!= null, but i found error. I can’t show toast and use setText() method.
public void run(){
Looper.myLooper();
Looper.prepare();
try {
while(!((line = in.readLine()).equalsIgnoreCase("quit"))){
if(line.isEmpty()){
System.out.println("there is no message");
}else{
Toast.makeText(this, "Message= " + line , Toast.LENGTH_SHORT).show();
msgbox.setText(line);
}
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Gagal mengirim ACK ke server");
}
}
what is your error?
can this code solve it?
runOnUiThread(…) Runs the specified action on the UI thread. If the current thread is the UI thread, then the action is executed immediately. If the current thread is not the UI thread, the action is posted to the event queue of the UI thread.