在Runnable中使用断点调试android应用程序[Android Studio]

Moa*_*had 2 debugging android breakpoints runnable android-studio

我需要调试我的应用程序,并调试runnable内的代码,并在应用程序中执行一些操作然后再次调试代码,但我不能这样做,我不能做任何操作,调试点立即激活.

代码:

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 .
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ski 6

对于runnables/async任务等Debug.waitForDebugger(),您设置断点的代码之前调用是很有用的:

...
Debug.waitForDebugger();
foo.bar();               # breakpoint on this line
...
Run Code Online (Sandbox Code Playgroud)