Tek Eye Logo

Tek Eye

Running an Android SDK Sample App

The 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 sample apps available to showcase Android features and provide example code that allows developers to see how to use the Android Application Programming Interface (API).

Update: From Android API 24, Nougat, the Google Android samples are online only. Plus this article was written prior to Google switching from Eclipse to Android Studio for app development. Therefore this article is now archived and kept for historial purposes only. To import a Google online sample into Studio close all open Android projects and select Import an Android code sample from the Welcome to Android Studio dialog. The SDK Manager can still be used to download Studio and Eclipse (legacy) samples for API 23 and earlier. Plus, here on Tek Eye there are lots of free Android Example Projects ready for importing into Studio.

Android Logo

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

Each SDK platform version provides Android sample source code projects, however, they must be selected for installation on your development machine using the SDK Manager program.

Getting Hold of the Android Samples

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.

Example 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.

The 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.

Eclipse File.New.Project menu options

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

Eclipse 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.

Build Progress Shown in the Status Bar

Run 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).

Eclipse Run Android App

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.

On Tek Eye there are lots of free Android Example Projects ready for importing into Studio.

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 appropriate Creative Commons License, see the Tek Eye Policies page for further details.

Author:  Published:  Archived:

ShareSubmit to TwitterSubmit to FacebookSubmit to Google+Submit to LinkedInSubmit to redditPrint Page

markdown CMS Small Logo Icon ↓markdown↓ CMS is fast and simple. Build websites quickly and publish easily. For beginner to expert.



Articles on:

Android, HTML, VPS, Computing, IT, Computer History, ↓markdown↓ CMS



Free Android Projects and Samples:

Android Examples, Android List Examples, Android UI Examples