Introduction to how to use the Android Studio debugging function

This article summarizes how to use the debugging function of Android Studio for your reference. The specific content is as follows

1. Set breakpoints

Select the code line to set the breakpoint, and click the left mouse button behind the area of ​​the line number.

2. Start a debug session

Click the little bug pointed by the red arrow to start debugging.

The Debug view appears below the IDE, and the red arrow points to the line of code where the debugger is currently staying. In the method f2(), line 11 of the program. The area where the red arrow hovers is the method call stack area of ​​the program. In this area, the methods used by the program execution to the breakpoint are displayed. The lower the method is called, the earlier it will be called.

3. Single-step debugging

3.1 step over

Click the button pointed by the red arrow, and the program executes one line down (if there is a method call in the current line, this method will be executed and returned, and then go to the next line)

3.2 step into

Click the button pointed by the red arrow, and the program executes one line down. If the line has a custom method, run into the custom method (the method that will not enter the official class library). Specific steps are as follows:

Set a breakpoint at the custom method f1() to execute debugging

click

3.3 Force step into

This button can step into any method while debugging.

3.4 step out

If you enter a method (such as f2()) during debugging and feel that there is no problem with the method, you can use stepout to jump out of the method and return to the next line of statement where the method is called. It is worth noting that this method has already executed.

3.5 Drop frame

After clicking this button, you will return to the calling place of the current method (as shown in the figure above, the program will return to main()) to re-execute, and the values ​​of all context variables will also return to that time. As long as there are superior methods in the call chain, you can jump to any one of them.

4. Advanced debugging

4.1 Debugging across breakpoints

Set multiple breakpoints and enable debugging.

To move to the next breakpoint, click as shown below:

The program will run the code that needs to be executed between one breakpoint and the next. If there is no breakpoint in the following code, clicking the button again will execute the program.

4.2 View breakpoints

Click the button pointed by the arrow to view the breakpoint you have set and set some properties of the breakpoint.

Arrow 1 points to the breakpoint you have set, and arrow 2 can set a conditional breakpoint (when a certain condition is met, the execution of the program is suspended, such as c==97). After finishing debugging, the set breakpoint should be deleted at arrow 1 (after selecting the breakpoint to be deleted, click the red minus sign above).

4.3 Setting variable values

After the debugging starts, you can assign a value to the specified variable in the area pointed by the red arrow (the left mouse button selects the variable, and the right mouse button pops up the menu to select setValue...). This feature can detect your conditional statements and loop statements more quickly.

Select view value when alt+f8 debug

F8 is equivalent to eclipse's F6 to jump to the next step

shift+f8 is equivalent to eclipse's f8 to jump to the next breakpoint, and also equivalent to eclipse's f7 to jump out of the function

F7 is equivalent to eclipse's f5 is to enter the code

alt+shift+f7 This is the forced entry code

ctrl+shift+f9 debug run java class

ctrl+shift+f10 to run java classes normally

command+f2 stop running

The above is the whole content of this article, I hope it will be helpful to everyone's study.

at last

If you want to become an architect or want to break through the 20-30K salary range, then don't be limited to coding and business, but you must be able to select models, expand, and improve programming thinking. In addition, a good career plan is also very important, and the habit of learning is very important, but the most important thing is to be able to persevere. Any plan that cannot be implemented consistently is empty talk.

If you have no direction, here I would like to share with you a set of "Advanced Notes on the Eight Major Modules of Android" written by the senior architect of Ali, to help you organize the messy, scattered and fragmented knowledge systematically, so that you can systematically and efficiently Master the various knowledge points of Android development.
insert image description here
Compared with the fragmented content we usually read, the knowledge points of this note are more systematic, easier to understand and remember, and are arranged strictly according to the knowledge system.

Full set of video materials:

1. Interview collection

insert image description here
2. Source code analysis collection
insert image description here

3. The collection of open source frameworks
insert image description here
welcomes everyone to support with one click and three links. If you need the information in the article, directly scan the CSDN official certification WeChat card at the end of the article to get it for free↓↓↓

Guess you like

Origin blog.csdn.net/weixin_43440181/article/details/130115997