final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 100ms
}
}, 100);
A Handler must always be linked to a Looper, which will actually process the Runnable you post(). The UI thread already comes with a Looper, so you can just make a new Handler() on the UI thread and post() Runnables directly to it. These Runnables execute on the UI thread. To have Runnables execute on another thread, you need to make a new thread, then Looper.prepare(), make a new Handler() and then Looper.loop(). Any Runnables posted to this new Handler will execute on this new thread. If you don't do all this, the post() will throw an exception.