The API Demos include sample code for many aspects of the Android APIs, from screen layout to Intent resolution.
Activity Hello World
Demonstrates a basic screen activity.
Code:
HelloWorld.java
Layout:
hello_world.xml
Save & Restore State
Demonstrates how an activity should save state when it is paused.
Persistent State
Demonstrates how you can save and restore preferences, which are stored even aft er the user closes the application.
Receive Result
Demonstrates how an activity screen can return a result to the activity that opened it.
Forwarding
Demonstrates opening a new activity and removing the current activity from the history stack, so that when the user later presses BACK they will not see the intermediate
Demonstrates how to make an activity with a transparent background.
TranslucentBlur
Demonstrates how to make an activity with a transparent background with a special android.content.Context#startService Context.startService} and {@link android.content.Context#stopService Context.stopService}.
Local Service Binding
Demonstrates binding to a service class LocalServic e that runs in the same process as the activity, to demonstrate using the {@link android.content. Context#bindS ervice Cont ext.bindService} and {@link android.content.Context#unbindS ervice
Cont ext.unindS ervice} methods with a service. This also shows ho w you can simplify working with a service when you know it will only run in your own process.
Remote Service Controller
Demonstrates starting a service in a separate proc ess, by assigning
android:process=":remote" to the service in the AndroidManifest.xml file.
Remote Service Binding
Demonstrates binding to a remote service, similar to the Local Servic e Binding sample, but illustrating the additional work (defining aidl interfaces) needed to interact with a service in another process. Also shows how a service can publish multiple interfaces and implement callbacks to its clients.
Service Start Arguments Controller
Demonstrates how you can use a Service as a job queue, where you submit jobs to it with {@link android.content.Cont ext#startService Context.startService} instead of binding to the service. Such a service automatically stops itself once all jobs have been processed. This can be a very convenient way to interact with a service when you do not need a result back from it.
Code:
ServiceStartArgumentsController.java ServiceStartArguments.java
Layout:
service_start_arguments_controller.xml
Alarm
Alarm Controller
Demonstrates two ways you can schedule alarms: a one-shot alarm that will happen once at a given time, and a repeating alarm that will happen first at a given time and then continually trigger at regular intervals after that.
Code:
AlarmController.java OneShotAlarm.java RepeatingAlarm.java
Layout:
alarm_controller.xml Alarm Service
such as retrieving recent e-mails.
Code:
AlarmService.java
AlarmService_Service.java
Layout:
alarm_service.xml
Notification NotifyWithText
Demonstrates popup notifications of varying length.
IncomingMessage
Demonstrates sending persistent and transient notifications, with a View object in the notification. It also demonstrated inflating a View object from an XML layout resource.
Search SearchInvoke
Demonstrates various ways in which activities can launch the Search UI.
SearchQueryResults
Demonstrates an activity that receives Search intents and handles them.
SearchSuggestionSampleProvider
Demonstrates how to configure and use the built -in "recent queries" suggestion provider.
Files
AdvancedPreferenc es.java
AlarmController.java
AlarmService.java
AlarmService_Service.java
AlertDialogSamples.java
ContactsFilter.java
ContactsFilterInstrumentation.java
ContactsSelectInstrumentation.java
CustomDialogActivity.java
CustomTitle.java
DefaultValues.java
DialogActivity.java
ForwardTarget.java
Forwarding.java
HelloWorld.java
IncomingMessage.java
IncomingMessageView.java
Intents.java
LauncherShortcuts.java
LaunchingPreferences.java
LocalSample.java
LocalSampleInstrumentation.java
LocalService.java
LocalServiceBinding.java
LocalServiceController.java
MenuInflateFromXml.java
MyPreference.java
NotificationDisplay.java
NotifyWithText.java
NotifyingController.java
NotifyingService.java
OneShotAlarm.java
PersistentState.java
PreferenceDependencies.java
PreferencesFromCode.java
PreferencesFromXml.java
ReceiveResult.java
RedirectEnter.java
RedirectGetter.java
RedirectMain.java
RemoteService.java
RemoteServiceBinding.java
RemoteServiceController.java
ReorderFour.java
ReorderOnLaunch.java
ReorderThree.java
ReorderTwo.java
RepeatingAlarm.java
SaveRestoreState.java
SearchInvoke.java
SearchQueryResults.java
SearchSuggestionSampleProvider.java
SendResult.java
ServiceStartArguments.java
ServiceStartArgumentsController.java
StatusBarNotifications.java
TranslucentActivity.java
TranslucentBlurActivity.java
VoiceRecognition.java
Content
Resources Styled Text
Demonstrates loading styled text (bold, italic) defined in a resource file.
Resources
Demonstrates loading styled strings from a resource file, and extracting the raw text.
Files
ReadAsset.java
ResourcesSample.java
StyledText.java
View
RelativeLayout 1. Vertical
Demonstrates a simple relative layout.
2. Simple Form
Demonstrates a more complex relative layout to create a form.
LinearLayout 1. Vertical
Demonstrates a simple LinearLayout, with child width set to WRAP_CONTENT.
2. Vertical (Fill Screen)
Demonstrates a simple LinearLayout, with child width set to FILL_PARENT.
3. Vertical (Padded)
Demonstrates a LinearLayout where one of the elements can expand t o fill any remaining screen space (weight=1).
4. Horizontal
Demonstrates a horizontal LinearLayout, plus an expanding column.
5. Simple Form
Demonstrates nested layouts to create a user form.
6. Uniform Size
LinearLayout which uses a combination of wrap_content on itself and fill_parent on its
7. Fill Parent
Demonstrates a horizontal linear layout with equally sized columns. Some columns force their height to match the parent.
8. Gravity
Demonstrates a simple linear layout with menu options demonstrating horizontal and vertical gravity options.
Demonstrates scrolling screen with buttons altermating with a text view.
2. Long
Demonstrates a longer scrolling screen similar to ScrollView1.
TableLayout 1. Basic
Demonstrates a basic TableLayout with identical children.
2. Empty Cells
Demonstrates a TableLayout with column-spanning rows and different child objects.
3. Long Content
Rows have different number of columns and content does n't fit on screen: column 4 of row 2 shrinks all of the other columns
4. Stretchable
Demonstrates a TableLayout with a stretchable column.
5. Spanning and Stretchable
Demonstrates a complex TableLay out with spanning columns and stretchable columns to create a menu-like layout.
6. More Spanning and Stretchable
Similar to example 5, but with an additional "checked" column.
7. Column Collapse
Similar to example 6, but now wit h buttons on the bottom of the screen that enable you dynamically hide or show columns.
8. Toggle Stretch
9. Toggle Shrink
Demonstrates the use of advanced gravity attributes, such as center_horizontal and right|bottom to align cell contents in a table.
12. Various Widths
Demonstrates the use of elements of various widths in a table.
Baseline
Demonstrates the use of the android:layout_alignBaseline XML attribute in various page layouts.
Demonstrates the default baseline alignment in a complex LinearLayout.
6. Multi-line
Demonstrates a baseline alignment with a multiline field.
7. Relative
Demonstrates baseline alignment in a RelativeLayout.
BaselineNested1
Demonstrates baseline aligning specific elements in three parallel vertical LinearLayout objects.
BaselineNested2
Demonstrates baseline aligning specific elements in three mixed vertical and horizontal LinearLayout objects.
BaselineNested3
Demonstrates baseline alignment within nested LinearLayout objects.
Radio Group Radio Group
Demonstrates using radio buttons and capturing the selected item.
ScrollBars 1. Basic
Demonstrates a scrollable LinearLayout object.
2. Fancy
Demonstrates a scrollable LinearLayout object with a custom thumb slider image.
Visibility Visibility
Demonstrates toggling the visibility of a View object between visible, invisible, and gone.
Lists 1. Array
Demonstrates binding a ListAdapter to a string array as a data source, and displaying the elements on the screen.
Demonstrates implementing a custom ListAdapter that includes separators bet ween some items.
6. ListAdapter Collapsed
Demonstrates another custom list adapter with that returns expandible items.
7. Cursor (Phones)
Demonstrates a list adapter where data comes from a Cursor object.
8. Photos
Demonstrates a list activity that uses a custom ListAdapter, setting the view for an
Custom CustomView
Demonstrates implementing a custom view subclass.
ImageButton ImageButton
Demonstrates an ImageButton: a button with an arbitrary graphic on it.
Date Widgets 1. Dialog
Demonstrates the DatePickerDialog and TimePickerDialog picker dialogs.
2. Inline
Demonstrates using a TimePicker directly in a layout without using a confirmation button or dialog.
Gallery 1. Icons
Demonstrates implementing a Gallery widget and extending GalleryAdapter to create a custom class to serve out source images to the widget.
2. People
Demonstrates populating a Gallery with images from the contacts photos.
Spinner Spinner
Demonstrates populating two Spinner widgets with values.
Grid
1. Icon Grid
Demonstrates populating a GridView widget with a list of applications using a custom ListAdapter object.
2. Photo Grid
Demonstrates populating a GridView widget with images using a custom ListAdapter object.
ImageSwitcher ImageSwitcher
Demonstrates using the ImageSwitcher widget with a custom Adapter.
TextSwitcher TextSwitcher
Demonstrates using the TextSwitcher widget.
Animation 1. Shake
Demonstrates a simple tweened animation (android.view. animation.Animation).
2. Push
Demonstrates a variety of trans formations (android. view.animation.Animation), including fading, motion, and rotation.
Controls
1. Theme White
Demonstrates a variety of common form type widgets, such as check boxes and radio buttons using the white theme.
2. Theme Dark
Demonstrates a variety of common form type widgets, such as check boxes and radio buttons using the dark theme.
Auto Complete 1. Screen Top
Demonstrates the use of A utoCompleteTextView, an autocomplete dropdown box below a text box, with data taken from an array.
2. Screen Bottom
Demonstrates an autocomplete box above a text box.
3. Scroll
Demonstrates an autocomplete text box in the midst of a vertical list.
4. Contacts
Demonstrates an autocomplete text box that gets its content from a database query.
5. Contacts with Hint
Demonstates an autocomplete text box that understands the * wildcard.
Progress Bar 1. Incremental
Demonstrates large and small rotating progress indicat ors that can be incremented or decremented in units.
2. Smooth
Demonstrates large and small continuously rotating progress indicators used to indicate a generic "busy" message.
3. Dialogs
Demonstrates a ProgressDialog, a popup dialog that hosts a progress bar. This example demonstrates both determinate and indeterminate progress indicators.
WindowPolicy's progress indicator feature.
Focus 1. Vertical
Demonstrates how to block selection of a specific screen element.
2. Horizontal
Demonstrates how t o change the order of which screen element is selected when t he user presses arrow keys.
BaselineNested1.java
BaselineNested2.java
BaselineNested3.java
Buttons1.java
ChronometerDemo.java
Controls1.java
Controls2.java
CustomView1.java
DateWidgets1.java
DateWidgets2.java
ExpandableList1.java
ExpandableList2.java
ExpandableList3.java
Focus1.java
Focus2.java
Focus3.java
Gallery1.java
Gallery2.java
Grid1.java
Grid2.java
ImageButton1.java
ImageSwitcher1.java
ImageView1.java
InternalSelectionFocus.java
InternalSelectionScroll.java
InternalSelectionView.java
LabelView.java
LayoutAnimation1.java
LayoutAnimation2.java
LayoutAnimation3.java
LayoutAnimation4.java
LayoutAnimation5.java
LayoutAnimation6.java
LayoutAnimation7.java
LinearLayout1.java
LinearLayout10.java
LinearLayout2.java
ProgressBar3.java
ProgressBar4.java
RadioGroup1.java
RatingBar1.java
RelativeLayout1.java
RelativeLayout2.java
ScrollBar1.java ShapeDrawable
Demonstrates creating Drawables in XML.
OpenGL|ES CameraPreview
Demonstrates capturing the image stream from the camera, drawing to a surface (extending SurfaceView) on a separate thread (extending Thread).
GL SurfaceView
Demonstrates how to perform OpenGL rendering in to a SurfaceView.
Code:
GLSurfaceViewActivity.java
Layout:
hello_world.xml
PolyToPoly
Demonstrates calling the {@link
android.graphics.Matrix.html#setPolyToPoly(float[],int,float[],int,int)} method to translate coordinates on a canvas to a new perspective (used to simulate perspective).
DrawPoints
Demonstrates using the {@link android.graphics.Paint} and {@link android.graphics.Canvas} objects to draw random points on the screen, with different colors and strokes.
PathEffects
Demonstrates the use of {@link android.graphics.Path} and various {@link android.graphics.PathEffect} subclasses.
SurfaceView Overlay
Shows how you can place overlays on top of a SurfaceView.
Code:
SurfaceViewOverlay.java, GLSurfaceView.java
Layout:
surface_view_overlay.xml
TouchPaint
AnimateDrawable.java
BitmapDecode.java
BitmapMesh.java
BitmapPixels.java
CameraPreview.java
Clipping.java
ColorMatrixSample.java
ColorPickerDialog.java
Compass.java
GLSurfaceViewActivity.java
GradientDrawable1.java
GraphicsActivity.java
Layers.java
ShapeDrawable1.java
SurfaceViewOverlay.java
Sweep.java
TextAlign.java
TouchPaint.java
TouchRotateActivity.java
TranslucentGLSurfaceViewActivity.java
TriangleActivity.java
TriangleRenderer.java
Typefaces.java
UnicodeChart.java
Vertices.java
Xfermodes.java
Text
Files
Link.java
LogTextBox.java
LogTextBox1.java
Marquee.java