Yaroslav Mytkalyk Yaroslav Mytkalyk - 3 months ago 11x
Android Question

Run Handler messages in a background thread

I want to run some Runnable in a background thread. I want to use Handler because it's convenient for delays.
What I mean is

handler.post(runnable, delay);

Where runnable should be run in background Thread.
Is it possible to create such Handler?
Is there a "background" Looper somewhere or how can I create it?

P.S. I know how to do it with a custom class extends Thread but it requires a little more coding effort than doing it the handler way. So please don't post other solutions or something like

handler.post(new Runnable() {
public void run() {
new Thread() {
public void run() {

I just wander if Handler can do it the "clean" way.


You can set up a Looper in a background thread using Looper.prepare() and Looper.loop.