Simple and practical debugging tips for Android Studio _android

Source: Internet
Author: User

When it comes to the debugging of Android studio, a lot of people may say, what's the point of this is not a breakpoint debugging, just at the beginning I think so, until I understand, only to find that debugging the original can play so cattle. I'll introduce each of them below.

Conditional breakpoint (Conditional breakpoints)

This debugging mode is my favorite, simply can not be convenient, the previous encounter in the loop break point, need to look at the value under a certain condition, I can only click again and again, until the conditions.

Then this conditional breakpoint change how to use it, in your breakpoint on the right button, will pop up a selection dialog box, in the inside of the condition box filled with the conditions you need to break, this program will meet you under the conditions of the breakpoint will stop. Below put a dynamic diagram, a look to understand, after a few skills will also attach a dynamic map to the image of the display.

Shortcut keys

• Click the right mouse button

Log breakpoint (Logging breakpoints)

This pattern is also quite useful, before debugging the program, if you need to output some variables, always need to write log in the code, and then rerun the program, this has to see the new output, now have a log breakpoint this artifact, it does not need. Here's how to do this, first or right click on the breakpoint, put the suspend into the unselected state, and then fill in the log evaluated below expression the information you need to output

Shortcut keys

• Click the right mouse button to select suspend

Temporary breakpoint (temporary breakpoints)

This breakpoint is removed after your first breakpoint has been stopped, which means it will only break once during debugging.

Shortcut keys

• Mouse: Alt + left mouse button in the breakpoint area click

Mac:cmd+alt+shift+f8

Windows/linux:ctrl+alt+shift+f8

Failure Breakpoint (Disable breakpoints)

This breakpoint is suitable for you do not want to delete this breakpoint, but do not want to let this breakpoint execution, so temporarily let him fail, this function, the feeling will not be very common, after all, create a breakpoint is clicked.

Shortcut keys

• Mouse: Alt + mouse button click on breakpoint

(Attachment Debugging) Attach Debugger

Before I knew it, I was debugging a program that would always need to click Debug mode, then let the program run again, and then put up with a fairly slow startup process until I encountered this pattern.

In this mode, you do not need to restart the app, direct click, you can debug, and in the encounter of others in testing your app, this time encountered problems, you only need to plug in your computer, open this, you can directly breakpoint debugging, very convenient.

Shortcut keys

• Mouse: Click Build->attach to Android process Select app

Evaluate expression (Evaluate Expression)

This feature is used to view the value of a variable during debugging, or to compute any complex custom expression. This function is also very useful when debugging, such as I want a variable before, I always need to pass the this pointer in the bottom variable, and then find the member variable, and after this, you can observe the variable, and do some expressions of the calculation

Shortcut keys

Alt+f8

Observation variable (Inspect Variable)

This function can directly observe the value of a variable, without the need to open the above Evaluate Expression dialog box, faster

Shortcut keys

alt+ The left mouse button click on the variable above

Tag object (Mark Object)

In the process of debugging, this method allows you to label a particular object so that you can identify the variable in the following breakpoint

Shortcut keys

• Right mouse button, select Mark Object

MAC:F3

windows/linux:f11

The above is a small set to introduce the simple and practical Android Studio debugging skills, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.