Yaroslav Mytkalyk Yaroslav Mytkalyk - 1 year ago 104
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download