Step 1 of android development: start the first Android Program

Source: Internet
Author: User

In the previous section, we have already talked about how to install and deploy the android development environment.

So today we are about to get started with the real "development" of android ~

# Tip: the compiling environment of this tutorial is Eclipse Indego + Android SDK r12 + ADT r12 on Mac OS X Lion #

All right, let's talk nonsense and start with the question:

In our last tutorial, we have completed the Eclipse + Android SDK + ADT environment settings. How can we use this powerful environment to start writing code?

First, create an Android virtual device.

# Tip: Android Virtual Device (AVD) is a Virtual machine used to simulate Android devices on a computer. It has a relatively independent architecture. The SDK already contains AVD Manager, which allows you to create and edit Virtual Devices. We can create and run multiple "Virtual Hardware" configurations and different versions of AVD on the same computer. Do not worry if the developer does not have an Android phone. The AVD that Google has prepared for us can basically complete almost all our development work (related sensors can be simulated using third-party development tools ). #

To create an AVD device, you can open the Manager by clicking the AVD Manager button on the Eclipse toolbar.

# Tip: Where is the button? Is the button of a robot drawing on the toolbar #

Next, we can click New on the right to add AVD.

In the pop-up window, we can see some options:

1: Name (Name): Name of the custom device. select according to your interests.

2: Target (Target Platform): We can set it according to the programming environment we want. Target of different versions can only be developed at the API level supported by the next version.

3: CPU/ABI: here we can specify the instruction set or processor binary interface supported by the simulation device. So far, AVD can only simulate devices based on the ARM instruction set, new improvements may occur in the future.

4: SD Card: set the size of the SD Card mounted on the machine

5: Snapshot: screen Snapshot

6: Skin (Skin): We can set the device resolution here. Common options include HVGA (320x480) and WVGA (800x480 ).

7: Hardware (Hardware): here we can set the "Hardware" of the device, such as adding an acceleration sensor and gyroscope.

After filling in the Name, we can Create AVD.

So far, we have completed the creation of AVD, and then we will build the Android program in Eclipse.

Click-> File> New-> Project

In the displayed window, choose Android> Android Project.

Next we need to fill in the Name, that is, your Name for the project. Here we call it "HelloWorld"

Next, we should note that we should select Build Target: the AVD platform we just created is Android 1.5 API Level 3.

Then, in the following Properties, we need to enter the Application name (which is the same as the project name by default, but we can change it to our favorite name), Package name (the Package name must be defined by ourselves, use ". ).

At the same time, we need to check Create Activity. Then you can click Finish to create a project.

# Activity is the visualization core of the Android program. Almost all visualization objects we can see are inherited from the Activity and its derived classes, which Contains functions such as onCreate and onStart used to control the lifecycle #

After clicking Finish, the project will be created. You can expand the Helloworld project to understand the structure of the Android project.

The src folder stores the source code you have written.

The gen folder is the code automatically generated by the Android SDK. Android SDK depends on R. java manages resources in a unified manner. For example, if we need to use a String constant, we can use the R. string. xxx to access the index value of this string constant.

The res folder is used to save various resource files for project development. drawable stores bitmap and other files, layout stores layout files, and values stores strings and other files.

After the project is created, we can run the Helloworld program on AVD.

But before running, we must associate it with a running mode. Click the Small Arrow next to the running button to bring up the menu and select Run Configerations. This is the running mode configuration window.

In this case, double-click the first item on the left: Android Application and create a new running mode,

First, we need to specify the running method name, then select the project to be executed, and then select the started Activity, as shown in. Click Apply now, and then click Run.

At this time, the ADT will automatically run AVD. After a long wait (the first open opportunity is long), we can unlock the screen, then we can see that our program has been executed (how important is there a large screen for development !) ~

Okay ~ My tutorial is like this. Not much. I wish you a pleasant stay ~

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.