How To Remove Background From Thread
I am using Timer to check a condition periodically and want to remove background if found true condition. But it is giving me an error. android.view.ViewRootImpl$CalledFromWrongTh
Solution 1:
Hi you can use at least two methods to do that:
1. runOnUIThread Activity's method
runOnUiThread(new Runnable(){
publicvoidrun() {
// UI code goes here
}
});
2. Handler
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
publicvoidrun() {
// UI code goes here
}
});
Solution 2:
Use handler to touch views in main thread like that:
HandlermHandler=newHandler();
t.schedule(newTimerTask(){
mHandler.post(newTimerTask(){
@Overridepublicvoidrun() {
if(!active){
fl.setBackgroundResource(android.R.color.transparent);// this line causing error !
}
}
});
}, 500,500);
Post a Comment for "How To Remove Background From Thread"