At this special time of the epidemic, I hope you pay attention to your safety and come on, Wuhan. The essay is mainly to record, but also to help students who do not understand

1. Create a breakpoint and start debug mode

First slightly right over the number of lines of code we want to break, click the left mouse button as shown:




Next, let’s break down each button action of Debug together

2.1, Step Over (F8)

This button does not automatically enter the method body. Instead, it executes the next step after running the entire method. For example, I’m currently running debug. If I keep clicking on this button, it will execute add() and sub() in onCreate(), and then end without printing in add and sub.

2.2 Step Into (F7)








2.3, Force Step Into





2.4, Step out





2.5, Run to Cursor

1. If in the debug we are currently running, if the current breakpoint is in onCreate() and the current breakpoint is in add(), click Run to Cursor, the breakpoint will indeed move to the next breakpoint and stay in sub().

2. If we are already inside the add() method and click Run to Cursor, we see that it just runs the for loop once and continues to block. The diagram below:


So what if we want to run directly to the next breakpoint sub() when we are already inside add()? Click to Resume the Program





3, Debug

3.1, Watches

If we debug, many variables may appear, and we want to observe only a few variables. We can add him to the watches. For example, the variable I in my add() method,

Method 1: In the Variables we observe, right-click the variable and select Add to Watches

Method 2: In our brand word interface, click the + sign, enter I in the input box, search, can also be added to the brand word, convenient for us to debug

3.2, the Set Value

For example, in our add() method, we have a for loop. Normally we debug from I =0 every time. If we want to debug directly from I =5, we can go to the Variables screen, find that variable Value, right-click Set Value, and type 5. I can skip the first few loops.

3.3. View all breakpoints

If you hit a lot of Breakpoints during development and forget to cancel them, you can click View Breakpoints to see all of them

3.4. Stop debugging

3.5. How to add debugging for already running programs without re-running the program?

I’m going to say a few more words here, because we’re adding debug to a program that’s already running, so if we go to a page, all of the code in onCreate() has already been executed, so if we click on a button, we can add debug to the method that we need to run. For example, first of all, if we have a normal program, we add a breakpoint to the click event.

Then, click Attach Debugger to Android Process

The following page pops up, click OK, and click the button to debug


Want to grow up with me? Please follow my official account