I want to implement a timer in my android game using following code. This code runs certain code after every second.
final Handler handler = new Handler();
Runnable runable = new Runnable() {
@Override
public void run() {
try{
//task to be done
handler.postDelayed(this, 1000);
}
catch (Exception e) {
// TODO: handle exception
}
finally{
//task to be done
handler.postDelayed(this, 1000);
}
}
};
handler.postDelayed(runable, 1000);
The handler is created in UI thread. Will such an infinite loop block the thread ? If not why not ?