Android Development Bug Special: Introductory article (i)

Source: Internet
Author: User

Objective:

This article will be reproduced in the wisdom of the author and source. Reserved

Original address: http://segmentfault.com/a/1190000004380690

Zhuge Liang is a good programmer, each of which is written in response to a different case. But a good programmer is a better bug than a good opponent. Six out of the mountain, seven into the central Plains, dedicated, heartily Zhuge Liang just because there is a wrong case-Ma Su, the entire structure was break.
A bug is really a very annoying thing, it always jumps out to mock you when you think you've conquered it.

How to win these annoying bugs? I want to start with Debug. Let's introduce the Debug method to the novice who has just come into contact with programming. After learning these methods, repeat the exercises. When you accumulate tens of thousands of effective code volumes, you will naturally find that your level is greatly improved.

Tool Description:

Android Studio: Almost all compilers will bring their own debug debugger, so let's talk about this first. I'll take Android studio as an example here. Android Studio is Google's launch of the software specifically with the development of Android, because targeted than eclipse strong, so inside the integration of a lot of plug-ins personally think more convenient than eclipse. Most Android developers now use this IDE.

Android Studio comes with simulator: Simply speaking Android is not like C or C + + or even simple Java programming.

It is from design to coding to debugging. All without a mobile phone, Android studio comes with a powerful simulator that can simulate a mobile phone on a computer. Assuming you don't consider the program's compatibility with real-world devices, this simulator is great. General procedures in the development phase of the need to be able to use the simulator to meet.

Cloud Phone : The simulator also has drawbacks. It is less efficient. And the implementation of the program on the real machine. Far more complex than simulators. So the developer of the program to write, but also need to use the real machine to debug. I'm not too reluctant to use my own phone to debug, so I'll use Testbird's cloud phone. They will provide hundreds of mainstream phones in the cloud, and you can use the IDE directly from Android Studio. To remotely connect these machines for debugging, is simply for debugging Android program tailored.
Testbird Official registration Address (now 260 yuan for the experience of the time of the event is January 1 to January 31)

Create an initial program:

First, after you have created a default blank project. We're going to add something to project so we can have something to adjust. Because this article is for beginners to see (Debugging will not you dare to call yourself veteran?) )。 We all know that an important concept in Android programming is MVC. The full name of MVC is the Model View controller, which is the abbreviation for the models-view-controller. In the model, we can do whatever. Since this involves structure and data types, this example is not covered.

View can be summed up-what you see on your phone is either a view or a view, but this is wrong and the view is not all visible. As for controller controllers, you can interpret them as your control logic.

In Android Studio default Project there was a textview and an envelope-like button, and we were able to make the following changes to this default project, such as: Adding a button button, The TextView display is the default "Hello world!" before the user presses the button. ”。 When the user presses the button, the TextView becomes the number of times pressed. I'll post the detailed steps here:

Import android.widget.*;//introduce Java package
...
TextView textview;//Create a TextView object
button button;//Create a button object
int count = 0;
...
include the following statement in the OnCreate () method:
Button = (button) Findviewbyid (R.id.button);
TextView = (TextView) Findviewbyid (R.id.textview);//These two words link the view with the controller, In other words, you have these two words about the operation of the view on your mobile phone. The ability to reflect your control logic is in the program ~

 public  void  btn1_click   (view view)  ' //button to make a reflection of the function.   {String str =  "---->"  + count; Textview.settext (str); count++;} 

Then execute the program to be able to, click on the number will be added one. Here is the first picture (I use a cloud phone, you can conditionally use their own mobile phone or simulator):

DEBUG:

First step, set breakpoints
Now the initial procedure is complete. Let's talk about debugging, Android debugging first you need to know where to break the point. It's not like the C language, just the C file where you want to play. There are two main types of files for Android, one of which is. java files. An. xml file.

The break point can only be hit in the. java file because the. java file is the control logic. While the. xml file can be understood as a view file or a layout file, the program logic process is never going to go there, even if there is no meaning whatsoever. Break point of the way is also very easy, just in a line of code with the left mouse button point of the red dot appears to indicate the break point success. For example, with:

Dot is the first step in using Debug, then just click on Run->debug "Run" to be able to.

When your program executes to the point where the breakpoint is located, the program will voluntarily pause, for example:

Suppose you are executing the program via debug phone will also be prompted. Everyone can see.


Then the program assumes that you are at the breakpoint and you see a row in the selected state. This time the program has been paused.


This time you can choose to continue to the next breakpoint or your own step-by-point tracking debugging:
Step-by-step commissioning (F8)

Executes directly to the next breakpoint (F9)

The core of the debug operation is just this simple three-step: Break point. Through debug execution program, according to their own need to choose the debug mode (debugging can also break points).

Today, we mainly give you a brief introduction of the debug, is the basic use of the way, the next section will explain in detail the use of debug methods and characteristics.

Android Development Bug Special: Introductory article (i)

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.