[Android Studio authoritative Tutorial] breakpoint Debugging and advanced debugging

Source: Internet
Author: User

Some people say that Android debugging is the most pit, then I can only say that you do not use it, I can say that Android Studio debugging is the best I have ever seen.

Okay, so start writing a simple debug program, let's go for a for loop.

?
12345678 <code class="language-java hljs ">for (int i = 0; i < 10; i++) {//获取当前i的值    int selector = i;    //打log查看当前i的值(此步多余,实际开发请忽略)    Logger.e("for当前的i的值:" + i);    //调用方法    stepNext(i);}</code>

Set breakpoints (click the red dot location to add or cancel breakpoints)

Click Debug mode to Run

View the Debug panel

First, simple commissioning 1. Step Over: Walk down

The current program run position, we see the value of I has been shown in the program code, the yellow code, this is the function of as, for our debugging, this is a very big benefit.

Click the single-step Debug button or press the shortcut key F8 to see the effect. Here we see that the value of the selector variable has come out selector:0 , and we are looking at the current value of the yellow position I is 0.

At this point we continue to F8, we switch to Logcat view log, I print out the value of I is 0,

We can see in the variables display panel that the value of I is 0,selector value is 0 in the cut-back debugger panel. As well as we can see in the Frames Control Panel where the current program can be displayed in: OnCreate (): 28, line 28th.

2. Step into: See how it Goes

For example, we call a method in the For loop stepNext(int i) , and when we come here to look at the running process in this method we can do this, and when we go to this method we can press F7, or the icon.

Then went to the Stepnext method.

Here print a log, we click F8 we look at Logcat, here I print the log is to do the tutorial, debugging we don't have to hit the log, just look at the display panel is OK

3. Force Step into: all methods See full

This is the realization that you can see all the methods that you call and let you follow it again, study the source code is very convenient to use

4. Step out: There is a breakpoint next, go through the breakpoint continue to go

Here if one of our processes, including the method of invocation, if there is a breakpoint to go to the next breakpoint, if there is no breakpoint, but in a call method, will jump out of this method, continue to go.

Vc/e0aosvtm49sd919ojujxiciavpg0kpgltzybhbhq9 "Write a picture here describing" src= "http://www.2cto.com/uploadfile/Collfiles/20150616/ 20150616083836160.png "title=" \ "/>

I now have the program position at the first breakpoint position (24 lines), and I have a breakpoint in the Stepnext method I'm calling, at which point I press the step out button to go to the breakpoint in Stepnext (39 lines). If I press step out again at this time Will go to the next executable code (30 lines) of the call of the Stepnext method

() If I am now in the Stepnext method, if I press step out at this point, I will go to the next executable code (30 lines) of the call of the Stepnext method.

5. Run to Cursor: Next breakpoint we'll see

This means that the position of the next breakpoint will be executed very quickly, and can be as static as any method called

Second, advanced debugging 1. Cross-Breakpoint debugging

If we set multiple breakpoints, now we need to jump directly to the next breakpoint, then just click on it.

2. Observing variables

If we want to observe the changes in the values of 1 or several variables, if we look at the variables display panel, if I have too many custom variables and system variables here, then it's hard to see, and we can do the following:
Click Watches, click on the + sign, then enter the name of the variable return to OK, and there will be history OH

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

3. Setting the value of a variable

In the program there are a lot of conditional statements and loop statements, debugging is also more time-consuming, we can quickly set the value of the variable to speed up the debugging, we can do the following:
Select the variable name in [Variables] and click [Right] to select [Set Value ...] or select direct F2 (e.g.) (For variables panel)

4. View Breakpoints

After the click we can see all the breakpoints, as well as the location code, you can also set some properties

5. Stop Debugging

Note that [Stop debugging] here is not to let the program stop, but to skip all debugging

Here our Android Studio breakpoint debugging and Advanced debugging is complete.

Interested children's shoes can follow my blog, my column will continue to update the Android Studio tutorial, as well as I/O assembly on the NDK configuration and compilation, I will also share to everyone.
And I received an invitation from CSND's instructor, and later I will record the use of these Android studio videos into a video published at Csdn College.

[Android Studio authoritative Tutorial] breakpoint Debugging and advanced debugging

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.