[Android development Basics] Run your application

Source: Internet
Author: User

Running Your App run Your application


Run on a Real Device
Run on the Emulator Run the application on the VM
If you create an Android project following the previous section, it contains a set of default "Hello World" source files that can be run correctly.

Running your application depends on two things: Whether you have a real Android-based device and whether you use Eclipse. This section describes how to install and run applications on real devices or the Andorid simulator, whether you are using Eclipse or the command line tool.

Before running your application, you should know several directories and files in the Android project.

AndroidManifest. xml
This manifest file describes the basic attributes of the application and defines each component in the application. You will learn more about the statements when learning more courses in the future.
Src/
This directory is the main directory of your source program. By default, a directory contains an Activity class, which runs when you click the application icon.
Res/
Contains several subdirectories, which are application resource files. The following are examples:
Drawable-hdpi/
It stores the drawable objects (bitmaps image) designed for high-resolution (hdpi) screens ). Other drawable directories contain resources (images) designed for other resolutions ).
Layout/
The file in this directory is used to define the user interface of the application.
Values/
This directory contains XML files of various resource sets, such as the definition of strings and colors.
When you build and run the default Android project, the default Activity class in the src directory starts to run and loads a layout file from the layout directory, the layout file contains a "Hello World" message. Although not excited, it is very important for you to understand how to build and run applications before implementing truly functional applications.


Run on a Real Device
Whether you are using Eclipse or the command line tool, you need:

Connect your Android devices and computers with a USB cable. If you are developing in Windows, you need to install the correct USB driver for the device. For more information about Driver Installation, see oem usb driver.
Make sure that the "USB debug" option on the device is enabled (mostly in "Settings"-> "application"-> "development" or in "Developer options" on systems above 4.0 ).
Run the application from Eclipse, open a project file, and click Run in the toolbar. Eclipse will install the application to the device you are connected to and start running it.

Run the application from the command line:

Switch to the root directory of your Android project and run:
Ant debug
Make sure that the Android SDK platform-tools/directory has been added to the "PATH" environment variable, and then execute:
Adb install bin/MyFirstApp-debug.apk
Find MyFirstActivity on your device and open it.
If you want to start adding something to the application, continue with the next lesson.

Run on the Emulator Run the application on the simulator
Whether you use Eclipse or the command line tool, you must first create an Android Virtual Device (AVD). AVD is an Android Simulator for device configuration. It allows you to change the configurations of different devices.


Figure 1. AVD manager shows several virtual devices.

Create an AVD:

Open the Android Virtual Device Manager:
In Eclipse, select Window> AVD Manager, or click the AVD Manager icon on the toolbar.
In the command line, switch to the <sdk>/tools/directory and execute:
./Android avd
On the Android Virtual Device Manager panel, click New.
Fill in the AVD details, give it a name, select the target platform, SD card capacity and screen size.
Click Create AVD
In Android Virtual Device Manager, select the new AVD and click Start.
After the simulator starts, unlock the simulator screen.
Run the application from Eclipse, open a project file, and click Run on the toolbar. Eclipse will install the application to your AVD and run it.

Or run your application from the command line:

Switch to the root directory of the Android project and run:
Ant debug
Make sure that the Android SDK platform-tools/directory is included in the PATH environment variable and then run:
Adb install bin/MyFirstApp-debug.apk
In the simulator, locate MyFirstActivity and open it.
Start to add something to the application. continue to the next lesson.


Author: beeboobeeboo

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.