This section includes samples for:
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 after 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 activity.
- Redirection
- Demonstrates how to save data to preferences and use it to determine
which activity to open next.
- Translucent
- Demonstrates how to make an activity with a transparent background.
- TranslucentBlur
- Demonstrates how to make an activity with a transparent background with
a special effect (blur).
- Dialog Activity
- An Activity that sets its theme to android:style/Theme.Dialog so that
it looks like a Dialog.
- Custom Title
- An Activity that places a custom UI in its title.
- Animation
- Demonstrates how to use custom animations when moving between activities.
- Activity Recreate
- Demonstrates how an Activity can cause itself to be recreated.
- Screen Orientation
- Demonstrates the different screen orientations an Activity can request.
- Soft Input Modes
- Demonstrates how different soft input modes set in an Activity's
window impacts how it adjusts to accommodate an IME.
- Intent Activity Flags
- Demonstrates various uses of Intent flags to modify an application
task's activity stack in common ways.
- Reorder on Launch
- Demonstrates how the activities in a task can be reordered. UI flow
goes through the activities ReorderOnLaunch,
ReorderTwo, ReorderThree,
and ReorderFour.
- Wallpaper Activity
- An Activity that uses android:style/Theme.Wallpaper to be displayed
on top of the system wallpaper.
Fragment
- Fragment Alert Dialog
- Demonstrates how to use a DialogFragment to show and manage an
AlertDialog.
- Fragment Arguments
- Demonstrates how a fragment can be initialized with arguments,
supplying them either as an argument Bundle at runtime or XML attributes
in a <fragment> tag.
- Fragment Context Menu
- Demonstrates how to display and respond to a context menu that is
display from a fragment's view hierarchy.
- Fragment Custom Animation
- Demonstrates the use of a custom animation for pushing and popping fragments
on the back stack.
- Fragment Dialog
- Demonstrates use of DialogFragment to show various types of dialogs.
- Fragment Dialog or Activity
- Demonstrates how the same Fragment implementation can be used to provide the UI
for either an Activity or Dialog.
- Fragment Hide Show
- Demonstrates hiding and showing fragments.
- Fragment Layout
- Demonstrates use of the <fragment> tag to embed a Fragment in
an Activity's content view layout, and making the layout change based on
configuration to achieve different UI flows.
- Fragment List Array
- Demonstrates use of ListFragment to show the contents of a simple ArrayAdapter.
- Fragment Menu
- Demonstrates populating custom menu items from a Fragment.
- Fragment Receive Result
- Demonstrates starting a new Activity from a Fragment, and receiving
a result back from it.
- Fragment Retain Instance
- Demonstrates a Fragment can be used to easily retain active state across
an Activity's configuration change.
- Fragment Stack
- Demonstrates creating a stack of Fragment instances similar to the
traditional stack of activities.
- Fragment Tabs
- Demonstrates implementing ActionBar tabs by switching between
Fragments.
Action Bar
- Action Bar Mechanics
- Demonstrates the basics of the Action Bar and how it interoperates with the standard options
menu. This demo is for informative purposes only; see Usage for an example of using the
Action Bar in a more idiomatic manner.
- Action Bar Tabs
- Demonstrates the use of Action Bar tabs and how they interact with other action bar
features. Also see the Fragment Tabs for a more
complete example of how to switch between fragments.
- Action Bar Usage
- Demonstrates simple usage of the Action Bar, including a SearchView as an action item. The
default Honeycomb theme includes the Action Bar by default and a menu resource is used to populate
the menu data itself. If you'd like to see how these things work under the hood, see
Mechanics.
- Settings Action Provider
- Shows how to implement an ActionProvider for launching the system settings that supplies a
menu item with a specialized action view and handles standard menu item clicks in one place.
- Share Action Provider
- Shows how to use a ShareActionProvider to embed sharing functionality in your application
via the streamlined sharing UI added in ICS.
- Display Options
- Shows how various Action Bar display option flags can be combined and their effects.
LoaderManager
- Loader Cursor
- Demonstrates use of LoaderManager to perform a query for a Cursor that
populates a ListFragment.
- Loader Custom
- Demonstrates implementation and use of a custom Loader class. The
custom class here "loads" the currently installed applications.
- Loader Throttle
- Complete end-to-end demonstration of a simple content provider that
populates data in a list through a cursor loader. The UI allows the list
to be populated with a series of items, showing how AsyncTaskLoader's
throttling facility can be used to control how much a Loader is refreshed
in this case.
Service
- Local Service
- Demonstrate the implementation of a service that runs in the same
process as its client(s). Shows how those clients can either start/stop it
with Context.startService and Context.stopService, or bind and call it with
Context.bindService and Context.unindService.
This also shows how you can simplify working
with a service when you know it will only run in your own process. The client
code for interacting with the service is in
Local Service Activities.
- Messenger Service
- Demonstrates binding to a Service whose interface is implemented with
the Messenger class. This is often an easier way to do remote communication
with a Service than using a raw AIDL interface. The client
code for interacting with the service is in
Messenger Service Activities.
- Remote Service Controller and
Remove Service Binding
- Demonstrates starting a service in a separate process, by assigning
android:process=":remote"
to the service in the
AndroidManifest.xml file. Shows how those clients can either start/stop it
with Context.startService and Context.stopService, or bind and call it with
Context.bindService and Context.unindService.
Binding is similar to the local service sample,
but illustrates 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
- Demonstrates how you can use a Service as a job queue, where you
submit jobs to it with 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.
- Foreground Service
- Shows how you
can write a Service that runs in the foreground and works on both pre-2.0
and post-2.0 versions of the platform. This example will selectively use
the new foreground APIs that were introduced in Android 2.0 if they are
available.
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
- Demonstrates how you can schedule an alarm that causes a service to
be started. This is useful when you want to schedule alarms that initiate
long-running operations, 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.
- Status Bar Notifications
- Demonstrates a variety of different notifications that can be posted in
the status bar, and a standard way for handling them.
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.
Misc
- Alert Dialog Samples
- Demonstrates various styles of alert dialogs.
- Device Admin Sample
- Demonstration of the implementation of a simple device administrator
and its use of the DevicePolicyManager.