Reputation: 21
Dear all I have an android activity and a normal .java class which contains an "onChange" function(the function is called whenever properties of my skype contact are changed)
When I try to call an alertdialog.show() in my onChange function, I got error "Can't create handler inside thread that has not called Looper.prepare()", what should I do to show a message in my activity? thanks in advance
Upvotes: 1
Views: 576
Reputation: 33792
class LooperThread extends Thread {
public Handler mHandler;
public void run() {
Looper.prepare();
mHandler = new Handler() {
public void handleMessage(Message msg) {
// process incoming messages here
}
};
Looper.loop();
}
}
From the android documentation :
Threads by default do not have a message loop associated with them; to create one, call prepare() in the thread that is to run the loop, and then loop() to have it process messages until the loop is stopped
Also never ever have UI calls in a (worker) Thread. It is bound to throw exceptions.
Upvotes: 1