Chapter 2 create the first program Hello Tank
Difficulty: Easy
Now, we have to really write the android program. Although the preceding installation process is so complex, it is very easy to write a program. In addition, in order to give everyone an intuitive understanding, this article will not describe the principle of the large segment, but will penetrate into the explanation of the principles and concepts in the coding process.
Let's open eclipse and choose File> New> project... from the menu...
Choose Android> Android Project
Below we need to enter some information about the project, because we want to review the classic game tank war, so our program is named Tank
In this way, an android project is created. We can see our project in the package explorer of Eclipse.
Toadt's blessing, although we only enter a few names, this project can actually run. Right-click the project name and choose run as> Android Application.
If nothing happens, you will see a mobile phone simulator started, and the program we just created will be run.
If you find that the simulator is started and the program is not running, you may need to start the program manually. Here we use an important tool ddms (davlik debug manager ). To run the ddms shortcut, click open perspective in the upper-right corner of eclipse. If no ddms exists in the pop-up list, click others
Select ddms
In this way, we open the ddms interface, which will be frequently used in the future.
It was just said that the simulator was started and the program was not run. It is likely that the connection between ddms and the simulator was lost during the simulator startup process. The solution is simple:
Click the toolbar under the devices tab and select reset ADB.
Right-click the project name and choose run as> Android Application.
In addition to right-clicking the running project, you can also use the run button on the toolbar to start the program.
The debug button is on the left of the running button, which will be frequently used in the future.
Now we have the first android that can be run. Although you may feel confused about the pile of files generated by the ADT, you do not know the "Hello world, it doesn't matter where the main comes from, but with the depth of this article, you will gradually become familiar with the directory structure of the android project, program design principles and methods, as well as debugging and deployment methods. Now, you can familiarize yourself with the operations of the simulator. Let's see you later.