When is run() called when you post a Runnable to a Handler?

301 Views Asked by At

I want to post() some Runnable's to a Handler I have created and run some code before and after the run() of the Runnable is called. Is there any easy way to do this by overriding the Handler class or similar?

Edit: I am using the pause method in the answer on this page: Android, pausing and resuming handler callbacks. Basically I want to inject a pause whenever the handler starts to run a Runnable (or Message) and then resume the handler externally.

1

There are 1 best solutions below

0
On BEST ANSWER

As @pskink mentioned the Runnable is called here,

@Override
public void handleMessage(Message msg) {
    if (isPaused) {
        stack.push(Message.obtain(msg));
    } else {
        super.handleMessage(msg);
    }
}

The Runnable that is posted is turned into a Message and then the Message is handled here.