Android training-run your application

Source: Internet
Author: User

Running Android applications depends on two things: 1. Whether you have an actual Android device; 2. Whether you are using eclipse.

This section describes how to install and run your applications on real devices and Android simulators.

Before running your application, take a look at the following directories and files in the android project:

Androidmanifest. xml

The configuration file introduces the basic features of the application and defines each component in the application. In future training courses, you will learn more statements in this document.

Src/

This is the directory of the main source code file of your application. By default, this directory contains an activity class that runs when an application is started using the application icon.

Res/

This directory contains several sub-directories of application resources, which are as follows:

Drawable-hdpi/

This directory is used to store objects (such as bitmaps) that can be drawn for high-density (hdpi) screens ). Other drawable targets include graphic resources for other screen density designs.

Layout/

This directory stores the files that define the user interface of the application.

Values/

This directory stores XML files containing other resources, such as character and color definitions.

When you compile and run this default Android Application, the default activity class is started and the layout file "Hello world" is loaded. This result is plain, but it is important that you understand how the application runs before you start development.

Run on an actual device

If you have an actual Android device, follow these steps to install and run the application:

1. Use a USB connector to connect your development machine to an Android device. If you are developing on a Windows system, you need to install the USB driver of the corresponding Android device. OEM
The USB driver documentation will help you install the driver.

2. Enable USB debugging on your Android device.

A. For most devices that have run android3.2, you will find this option in Settings> Applications> development;

B. On devices later than android4.0, this option is available in settings-> developer options.

Note:After android4.2, developer options is hidden by default. To make this option available, go to settings-> about phone options and click build number seven times. Go back to the previous screen and find developer options.

To run the application in eclipse, open a file in the project and click the run button in the toolbar. Eclipse will install the application on the connected device and start it.

The following is how to run your application in the command line:

1. Enter the root directory of your android project in the command line window and execute the following command:

Ant debug

2. Make sure that the platform-toos/directory of the android SDK is included in your path environment variable, and then execute:

adb install bin/MyFirstApp-debug.apk

3. FindMyfirstactivityAnd open it.

Run on Simulator

Whether you use eclipse or command line, to run your application on the simulator, you must first create an android Virtual Device (AVD ). An AVD is a device configured for the android simulator. It simulates different devices.

Follow these steps to create an AVD:

1. Start the android Virtual Device Manager, as shown in Figure 1:

A. in eclipse, click the android Virtual Device Manager button in the toolbar.

B. In the command line window, go to the <SDK>/tools/directory and execute the following command:

Android AVD

Figure 1. AVD manager.

2. In the android Virtual Device Manager window, click New.

3. Fill in the AVD details in the pop-up window. Including the virtual device name, target platform, SD size, and skin (hvga by default ).

4. Click Create AVD.

5. select a new AVD In the android Virtual Device Manager and click the start button.

6. Unlock the simulator screen after the simulator starts.

To run an application from eclipse, open a file in your project and click the run button in the toolbar. eclipse will install the application on AVD and start it.

The following method is run in the command line:

1. Enter the root directory of your project in the command line window, and then execute the following command:

Ant debug

2. Make sure that the platform-toos/directory of the android SDK is included in your path environment variable, and then execute:

adb install bin/MyFirstApp-debug.apk

3. FindMyfirstactivityAnd open it.

 

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.