Debug android application with break point in Runnable [Android Studio]
Asked Answered
O

1

5

I need to debug my application and debug the code is part of Runnable and do some actions in application then debug the code again, but I can't do it, I can't do any actions as debug point is fired immediately.

code :

public class UpdateHandler {

    public static Handler getHandler() {
        if (sHandler == null) {
            HandlerThread looper = new HandlerThread("update Handler");
            looper.start();
            sHandler = new Handler(looper.getLooper());
        }

        return sHandler;
    }
}


UpdateHandler.getHandler().post(new Runnable() {
    @Override
    public void run() {
        update();
    }
});

public void update() {
    // i put the debug point here .
}
Overplay answered 6/5, 2015 at 13:18 Comment(0)
D
11

For runnables/async tasks etc it is useful to call Debug.waitForDebugger(), prior the code you set the breakpoint on:

...
Debug.waitForDebugger();
foo.bar();               # breakpoint on this line
...
Debit answered 6/5, 2015 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.