CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch views
Look like you are on the wrong thread. Try using a Handler to update the GUI on the right thread. See Handling Expensive Operations in the UI Thread example from android.com. Basically you would wrap byeSetup
in a Runnable
and invoke it with a Handler
instance.
Handler refresh = new Handler(Looper.getMainLooper());
refresh.post(new Runnable() {
public void run()
{
byeSetup();
}
});
when the change involves to the main thread (UiThread). Use it inside of another Thread to changes any view.
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO your Code
et_Pass.setText("");
}
});
Expanding on willcodejavaforfood's answer for clarity & implementation...
I got this to work and below is how I did it. I'm running multiple processing threads in a Service so other solutions that run in Activity don't work, like runOnUiThread(new Runnable() {}...
Put this at the top of your service class so it's accessible everywhere in this class:
Handler handler;
Put this in your service class onCreate method or something that loads on Service main thread
handler= new Handler(Looper.getMainLooper());
Put this inside your additional thread to 'post back' code to get run in UI or service UI (whatevers its called):
handler.post(new Runnable() {
public void run() {
playNext(); //or whatever method you want to call thats currently not working
}
});