The use of code debugging techniques under Android Studio

Source: Internet
Author: User

Remember when you first started to learn Java, every time you encounter debugging program on Eclipse is the syso+ shortcut keys, Use System.out.printLn. Output statement to debug Java program, Ha ha, originally felt really convenient, and then slowly step into the Android, and then use the Android version of Eclipse, in the Android code is of course to eliminate Java output statements, and then with the output log several ways to debug, occasionally also will use the Toast debugging (embarrassing), Eclipse version of the debug mode was not how to use the habit, will only be simple single-step debugging, and then wasted, although debugging a bit of trouble, but with a handy is also so-so, but the complex program crashes, the log output although can slowly find the problem lies, But it took a long time, and finally, Google no longer recommended eclipse as a development software for Android, but instead used Android studio as a standard development tool. So according to the company's needs, but also began to use as to develop software, the following is their own tools in the Android Studio, using debug breakpoint debugging some basic skills.

One of two ways to debug:

The difference between debug and attach process two is introduced first:
1.debug button: Install the running program in debug mode, breakpoints can be set before running the program, or after running the program.

2.attach process button: Compared to debug mode, is to debug the app is currently in the running state, be able to attach the debugger to any running process, this is our most common debugging mode.

Two. Single-Step debugging area

In the single-step debugging area There are step over, step into, force step into, step out, and drop frame.

1.Show Execution Point button

Click this button and the cursor will navigate to the location you are currently debugging.

2.Step over Button press F8

Stepping over, clicking this button will cause the program to execute down one line. If the current row is a method call, the method called by this line is executed and then to the next line.

3.Step into Button Press F7

  

Stepping in, doing so causes the program to execute down one line. If the row has a custom method, proceed inside the method and be aware that if it is a method in the class library, it will not go inside the method

4.Force Step into button

Forced stepping, similar to the step into function, is the main difference: if the current line has any method, regardless of whether the method is defined by us or provided by the class library, we can jump into the inside of the method to continue execution. To research the source code has certain help.

5.step out

If you enter a method () while debugging, and feel that the method is not a problem, you can use StepOut to jump out of the method and return to the next line of statements where the method is being used. It is worth noting that the method has been executed.

6.Drop Frame

 

Break execution, click the button, you will return to the current method's call to re-execute, and all the value of the context variable back to that time. You can jump to any of these methods as long as there is a parent method in the call chain.

7.Run to Cursor

You can ignore a breakpoint that already exists and jump to the location where you specified the cursor.

Three. Breakpoint Management Area

1.resume Program Press F9

This operation has the meaning of the recovery application, but there are two behaviors:
1. When the app is paused, clicking the button will restore the app to run.
2. In many cases, we will set multiple breakpoints for debugging. In some cases, we need to move from the current breakpoint to the next breakpoint, the code between the two breakpoints is automatically executed, so that we do not need to step-by-step debugging to the next breakpoint, save time and effort.

2.pause Program

Clicking this button pauses the execution of the app. If you want to recover, you can use the Resume program mentioned below.

3.stop

Clicking this button terminates the current process with the associated closing script. In other words, there may be different stopping behavior for different types of projects, such as: For normal Java projects, clicking on this button means exiting debug mode, but the app will also perform. And in Android, click the button, This means that the app is finished running.

4.View Breakpoints

Click this button will go to the breakpoint management interface, where you can view all breakpoints, manage or configure the behavior of breakpoints, such as: Delete, modify property information, etc.:

  

5. Setting the value of a variable

After debugging starts, the red arrow points to the area can assign a value to the specified variable (left mouse button to select the variable, right-click Pop-up menu select SetValue ... )。 This feature allows you to detect your conditional statements and loop statements more quickly.

Finally, the Debug debug mode under Android Studio is very powerful, there are a lot of things not to say, and so on when it comes to the time to add one by one.

The use of code debugging techniques under Android Studio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.