[Android Studio authoritative tutorial] breakpoint debugging and advanced debugging

Source: Internet
Author: User

[Android Studio authoritative tutorial] breakpoint debugging and advanced debugging

Some people say that Android debugging is the most difficult, so I can only say that you will not use it. I can say that debugging of Android Studio is the best I have ever seen.

Now, let's start writing a simple debugging program. Let's start with a for loop.

For (int I = 0; I <10; I ++) {// obtain the current I value int selector = I; // log to view the current I value (this step is redundant, please ignore the actual development) Logger. e ("for current I value:" + I); // call the method stepNext (I );}

Set the breakpoint (click the red dot to add or cancel the breakpoint)

Click debug to run

View debugging panel

1. simple debugging 1. step over: step by step

The position where the current program is running. We can see that the value of I has been displayed in the program code. In the yellow code, this is the AS function. for debugging, this is a huge benefit.

Click the single-step debugging button or press the shortcut key F8 to see the effect. Here we can see that the value of the selector variable has come out.selector:0, Let's see if the current value of the yellow position I is 0.

At this time, we continue F8. We switch to logcat to view the log. The I value I printed is 0,

We switch back to the Debugger panel. We can see that in the Variables display panel, the value of I is 0, and the value of selector is 0. The Frames control panel shows that the current program is located in rows 28 and 28th of onCreate.

2. step into: view the method to go in

For example,stepNext(int i)Method, when we want to see the running process in this method, we can do this, when we go to this method, we can press F7, or the icon such.

Then the stepNext method is used.

A log is printed here, and we can click F8 to check the Logcat. Here the log I printed is used for tutorial purposes, after debugging, you don't need to log it. You can view the display panel directly.

3. force step into: all methods are complete.

This shows that the implementation of all the methods you call will let you follow it again. It is very convenient to study the source code.

4. step out: There is a breakpoint next, and the breakpoint continues.

Here, if one of our processes includes the called method, and a breakpoint goes to the next breakpoint, if there is no breakpoint, but in a called method, the method will jump out and continue.

Vc/E0aOsvtm49sD919OjujxiciAvPg0KPGltZyBhbHQ9 "here write picture description" src = "http://www.bkjia.com/uploads/allimg/150618/041AB956-13.png" title = "\"/>

() I am currently in the first breakpoint position of the Program (24 rows), and The stepNext method I call also has a breakpoint, at this time, when I press the step out button, I will go to the breakpoint (39 rows) in stepNext. If I press step out again, I will go to the next executable code (30 rows) called by the stepNext method)

() If my current program is located in the stepNext method, if I press step out, the next executable code (30 rows) that is called by the stepNext method will be displayed)

5. run to Cursor: For the next breakpoint, see

This means that it will soon be executed to the next breakpoint location, and can be static as any called method.

Ii. Advanced debugging 1. Cross-breakpoint debugging

If we have set multiple breakpoints, and now we need to jump directly to the next breakpoint, click it.

2. Observe Variables

If we want to observe the changes of values of one or more Variables, if we observe in the Variables display panel, if I have too many custom Variables and system Variables, so it's hard to observe. We can do the following:
Click Watches, click the plus sign, and enter the variable name and press Enter. It will be OK, and there will be a history record.

If the variable name is long, we can do this:
Select the variable name in [Variables] and click [Right-click], select [Add to Watches], and then the Watches panel will have

3. Set the variable value

There are many condition statements and loop statements in the program, and debugging is time-consuming. We can quickly set the value of the variable to speed up debugging. We can do the following:
Select the variable name in [Variables] and click [Right-click]. Select [Set Value...] or select F2 directly (for example) (For the Variables panel)

4. View breakpoints

After clicking, we can see all the breakpoints and the location code, and set some attributes.

5. Stop debugging

Note that [Stop debugging] does not stop the program, but skips all debugging tasks.

Now we have finished breakpoint debugging and advanced debugging for Android Studio.

If you are interested, follow my Blog. My column will continue to update the Android Studio tutorial and the NDK configuration and compilation at the 2015 I/O conference, I will share it with you all.
I also received an invitation from CSND lecturers. Later I will record these Android Studio tutorials as videos and publish them to the CSDN Institute.

/*** -------------- * Welcome to reprint | reprinted please note * -------------- * if it is helpful to you, please click | top | * -------------- * Please keep humble | you will go further * -------------- * @ author zsl * @ github https://github.com/yy1300326388 * @ blog http://blog.csdn.net/yy1300326388 */

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.