Android Studio 线程调试 [英] Android Studio threaded debugging

查看:40
本文介绍了Android Studio 线程调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Android Studio 1.1 调试多线程应用时遇到问题.似乎当遇到断点时,所有其他线程也会停止,而不仅仅是带有断点的线程.我在 Activity 的 onCreate 中使用以下方法创建了一个简单的测试应用程序.

I've been having trouble debugging a multithreaded app with Android Studio 1.1. It seems as if when a breakpoint is hit all other threads also stop, not just the one with the breakpoint. I created a simple test app with the following method in the Activity's onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Thread a = new Thread("thread-a") {
        @Override
        public void run() {
            Log.v("thread", "thread-a");
        }
    };

    Thread b = new Thread("thread-b") {
        @Override
        public void run() {
            Log.v("thread", "thread-b");
        }
    };

    a.start();
    b.start();
}

我在线程 a 和线程 b 的 Log.v 行设置断点,然后在我的 Lollipop Nexus 5 上以调试模式运行它.

I set breakpoints at the Log.v lines in thread-a and thread-b and then I run it in debug mode on my Lollipop Nexus 5.

当应用程序启动时,它遇到了线程 a 中的断点,但我注意到的第一个问题是应用程序的 UI 是空白的,就像主线程暂停一样.接下来,我看到 thread-b 中的断点也被命中,所以我在 Android Studio 的调试器中拉出 Threads 视图,但是当我去展开 thread-b 箭头时,那里什么也没有.当我展开主线程时,它显示它在 onStart() 的某处暂停.

When the app starts it hits the breakpoint in thread-a but the first problem I notice is that the app's UI is blank as if the main thread is paused. Next I went to see that the breakpoint in thread-b is also hit so I pull up the Threads view in Android Studio's debugger but when I go to expand the thread-b arrow there's nothing there. When I expand the main thread it shows it is paused somewhere in onStart().

我做错了什么还是这个调试器不能同时调试多个线程?

Am I doing something wrong or is this debugger incapable of debugging multiple threads at once?

推荐答案

在 IntelliJ IDEA(并且 Android Studio 是基于 IntelliJ 的)中,当您放置断点时,如果您右键单击它会显示一个对话框,您可以选择是暂停所有线程(默认)还是仅暂停该线程.

In IntelliJ IDEA (and Android Studio is based on IntelliJ), when you place a breakpoint, if you do right click over it a dialog is displayed and you can select whether to pause all threads (the default) or only that thread.

您正在暂停所有线程,因为这是默认设置.

You are pausing all the threads as it is the default setting.

这篇关于Android Studio 线程调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆