Android Studio breakpoint debugging

Overview

As we all know, breakpoint debugging is a necessary skill for a qualified programmer. Breakpoint debugging can help us view the values ​​of each variable during each step of the program. Learning to debug can help us save a lot of time for troubleshooting. Let's take a look at the methods and techniques of debugging in Android Studio.
There are two debugging modes in Android Studio which are

  • Debug mode
  • Attach mode

Insert picture description hereThere is no big difference in the use of the two modes. Debug mode directly clicks the button to run debugging. In Attach mode, after the program starts, click the application that needs to be debugged.
Insert picture description here
Insert picture description here
# Debug interface overview

Debugging method

Step 1: add test code

We first MainActivity .javaadd some code in

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            list.add(getSting(i));
            setInto(i);
            Log.i("MainActivity", "这是第" + i + "条数据");
        }

    }

    public String getSting(int i) {
        return ("第" + i + "条数据");
    }

    public void setInto(int i) {
        Log.i("MainActivity", "i=" + i);
    }
}

Step 2: add breakpoints

During debugging or before debugging, click on the left side of the editing area to
Insert picture description here
add a debug breakpoint. Click again on a debug breakpoint that has been added to cancel the line breakpoint
Insert picture description here

Step 3: Commissioning

show Execution point

 功能:显示执行点:点击该按钮,光标将定位到当前正在调试的位置
快捷键:Alt + F10

Insert picture description here
Insert picture description here

Step Over

 功能:单步跳过,点击该按钮表示程序将执行下一行,如果该行是一句代码直接执行到下一行,如果该行是
 一个方法, 不会进入该方法,直接执行到下一行。
快捷键:F6

Insert picture description here
Insert picture description here

Step Into

功能:单步跳入,点击该按钮表示程序将执行下一行,如果该行是一个方法, 会进入该方法继续执行。
快捷键:F5

Insert picture description here

Insert picture description here

Force Step Into

功能:单步强制跳入,点击该按钮表示程序将执行下一行,如果该行是一个方法, 会进入该方法继续执行。
该操作和前面的Step Into的区别在于:Step Into 遇到系统方法不会强制进入,该方法遇到系统方法也
会强制进入。
快捷键:Alt + shift + F7

Insert picture description here

Step Out

Insert picture description here

功能:跳出前面step into 进入的方法,如果需要跳出的该方法有断点就不会跳出该方法,而会进入该方法下个断点
快捷键:F7

Insert picture description here

run to Cursor

Insert picture description here

功能:跳到下一个断点
快捷键:Ctrl + R

Insert picture description here
This function can also be achieved by clicking the green button on the left
Insert picture description here
Insert picture description here

View breakpoint

Insert picture description here
If we want to see where the breakpoints are hit, click this button to
Insert picture description here
uncheck the breakpoints
Insert picture description here

Modify variable value

In the variable area, right-click set value to modify the value during variable operation
Insert picture description here

Stop debugging

Insert picture description here
If you want to end the debugging process, click this button
Insert picture description here

Published 14 original articles · won 27 · views 3341

Guess you like

Origin blog.csdn.net/huweiliyi/article/details/105486756