Running an Android SDK Sample App

How to Load and Run a Sample Program from the Android SDK

The Android Robot LogoThe Android Software Development Kit (SDK) gets updated with new version platforms for each new release of the Operating System (OS). Each version platform can be loaded onto your development machine with SDK Manager.exe. There are available sample Applications (Apps) to showcase Android features and provide example code that allows developers to see how to use the Android Application Programming Interface (API).

Getting Hold of the Android Samples

Each SDK platform version provides Android sample source code project, however, they must be selected for installation on your development machine using the SDK Manager program. Run SDK Manager and wait for it to finish doing it’s checks. Expand the required Android Version folder to see and select the Samples for SDK option.

Exmaple Apps can be Loaded with the SDK Manager

Once the samples have been installed they will be found in the android-sdk/samples folder in the Android SDK’s install directory. (On Windows this may be under the Local Settings/Application Data folder, e.g. C:\Documents and Settings\John Doe\Local Settings\Application Data\Android, or wherever you chose to install it.) There will be a folder for each Android API version for which you chose to install the samples, called android-x where x is the API version.

Android SDK Samples

See our article Use Android SDK Samples for Guidance to see a list, and brief description, of the example Apps supplied with the various Android versions.

Eclipse File.New.Project menu optionsThe samples can be run on an Android Virtual Device (AVD) or physical device by creating a new Android project in Eclipse and selecting the sample to load. Use the Eclipse File then New menu option to select Project.

In the New Project dialog under the Android option select Android Sample Project and press the Next button.

Select Android Sample Project

Choose the Android SDK platform version to see the samples available (you will need to choose Android 2.1 or later). Press the Next button again.

Select Samples Android Versions

Finally select the required sample to use to create the project to run, and then press the Finish button.

Select the Android Sample To Load into a Project

Build Progress Shown in the Status BarEclipse will create a new project in the Workspace using the sample’s name as the project name. Then the sample’s source files are copied into the Workspace and added to the project. The project is then compiled and will be ready to run on an AVD or physical device. Whilst the project is being prepared for execution a message will be displayed in the Eclipse status bar.

Eclipse Run Android AppRun the new project to see the sample in action (ensure you have a physical device plugged into the development machine or have an AVD configured, see Set Up an Android Virtual Device for App Testing). The Eclipse Run As dialog is likely to display when the sample is first executed. Select Android Application and then the OK button (subsequent executions will not bring up this dialog).

Eclipse Run As Dialog

Have a play with the example Android programs to get an understanding on what can be coded using Eclipse and Java for Android App development. The good thing about the Android OS in general is that there are plenty of Android sample projects with source code available, allowing you to drill down into the Java and XML to see to achieve the desired functionality.

API Demos Sample Running

Notes:

  1. It is possible to add your own projects to the existing samples, simply export the required code to a new directory in the samples location.
  2. If the samples have been moved from their original install directory the Android Sample Project option on the New Project dialog cannot be used. Instead use Android Project from Existing Code.

See Move Android Code Between PCs Running Eclipse for details on the above points.

Acknowledgements

The Android Robot is reproduced from work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

One thought on “Running an Android SDK Sample App

  1. Pingback: Use Android SDK Samples for Guidance | Tek Eye

Leave a Reply

Your email address will not be published. Required fields are marked *

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.