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

查看:1540
本文介绍了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和线程中的Log.v行设置断点b然后我在我的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视图但是当我去扩展线程-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天全站免登陆