Android Guides | Samples

Android.OS Namespace

Remarks

Provides basic operating system services, message passing, and inter-process communication on the device.

Classes

TypeReason
AsyncTask

Developer Guides

Usage

java Example

 private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i

java Example

 new DownloadFilesTask().execute(url1, url2, url3);

AsyncTask's generic types

  1. Params, the type of the parameters sent to the task upon execution.
  2. Progress, the type of the progress units published during the background computation.
  3. Result, the type of the result of the background computation.

java Example

 private class MyTask extends AsyncTask<Void, Void, Void> { ... }

The 4 steps

  1. Android.OS.AsyncTask`3.onPreExecute() , invoked on the UI thread before the task is executed. This step is normally used to setup the task, for instance by showing a progress bar in the user interface.
  2. AsyncTask`3.DoInBackground , invoked on the background thread immediately after Android.OS.AsyncTask`3.onPreExecute() finishes executing. This step is used to perform background computation that can take a long time. The parameters of the asynchronous task are passed to this step. The result of the computation must be returned by this step and will be passed back to the last step. This step can also use Android.OS.AsyncTask`3.publishProgress(Progress...) to publish one or more units of progress. These values are published on the UI thread, in the Android.OS.AsyncTask`3.onProgressUpdate(Progress...) step.
  3. Android.OS.AsyncTask`3.onProgressUpdate(Progress...) , invoked on the UI thread after a call to Android.OS.AsyncTask`3.publishProgress(Progress...). The timing of the execution is undefined. This method is used to display any form of progress in the user interface while the background computation is still executing. For instance, it can be used to animate a progress bar or show logs in a text field.
  4. AsyncTask`3.OnPostExecute , invoked on the UI thread after the background computation finishes. The result of the background computation is passed to this step as a parameter.

Cancelling a task

Threading rules

Memory observability

Order of execution

AsyncTask+StatusIndicates the current status of the task.
AsyncTask<TParams,TProgress,TResult>

Developer Guides

Usage

java Example

 private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i

java Example

 new DownloadFilesTask().execute(url1, url2, url3);

AsyncTask's generic types

  1. Params, the type of the parameters sent to the task upon execution.
  2. Progress, the type of the progress units published during the background computation.
  3. Result, the type of the result of the background computation.

java Example

 private class MyTask extends AsyncTask<Void, Void, Void> { ... }

The 4 steps

  1. Android.OS.AsyncTask`3.onPreExecute() , invoked on the UI thread before the task is executed. This step is normally used to setup the task, for instance by showing a progress bar in the user interface.
  2. AsyncTask`3.DoInBackground , invoked on the background thread immediately after Android.OS.AsyncTask`3.onPreExecute() finishes executing. This step is used to perform background computation that can take a long time. The parameters of the asynchronous task are passed to this step. The result of the computation must be returned by this step and will be passed back to the last step. This step can also use Android.OS.AsyncTask`3.publishProgress(Progress...) to publish one or more units of progress. These values are published on the UI thread, in the Android.OS.AsyncTask`3.onProgressUpdate(Progress...) step.
  3. Android.OS.AsyncTask`3.onProgressUpdate(Progress...) , invoked on the UI thread after a call to Android.OS.AsyncTask`3.publishProgress(Progress...). The timing of the execution is undefined. This method is used to display any form of progress in the user interface while the background computation is still executing. For instance, it can be used to animate a progress bar or show logs in a text field.
  4. AsyncTask`3.OnPostExecute , invoked on the UI thread after the background computation finishes. The result of the background computation is passed to this step as a parameter.

Cancelling a task

Threading rules

Memory observability

Order of execution

BadParcelableExceptionThe object you are calling has died, because its hosting process no longer exists.
BaseBundleA mapping from String values to various types.
BatteryHealthEnumerates values returned by several types.
BatteryManagerThe BatteryManager class contains strings and constants used for values in the Intent.ActionBatteryChanged Intent, and provides a method for querying battery and charging properties.
BatteryPluggedEnumerates values returned by several types.
BatteryPropertyEnumerates values returned by several types.
BatteryStatusEnumerates values returned by several types.
BinderBase class for a remotable object, the core part of a lightweight remote procedure call mechanism defined by BinderConsts.
Binder+InterfaceConsts
BinderConstsBase interface for a remotable object, the core part of a lightweight remote procedure call mechanism designed for high performance when performing in-process and cross-process calls.
BuildInformation about the current build, extracted from system properties.
Build+VERSIONVarious version strings.
Build+VERSION_CODESEnumeration of the currently known SDK version codes.
BuildVersionCodesEnumerates values returned by several types and taken as a parameter of the EditorInfo.MakeCompatible member.
BundleA mapping from String values to various Parcelable types.
Bundle+InterfaceConsts
CancellationSignalProvides the ability to cancel an operation in progress.
CancellationSignal+IOnCancelListenerListens for cancellation.
ConditionVariableClass that implements the condition variable locking paradigm.
CountDownTimerSchedule a countdown until a time in the future, with regular notifications on intervals along the way.
DeadObjectExceptionThe object you are calling has died, because its hosting process no longer exists.
DebugProvides various debugging methods for Android applications, including tracing and allocation counts.
Debug+InstructionCountAPI for gathering and querying instruction counts.
Debug+MemoryInfoThis class is used to retrieved various statistics about the memory mappings for this process.
Debug+MemoryInfo+InterfaceConsts
DebugShowEnumerates values returned by several types and taken as a parameter of the Debug.PrintLoadedClasses member.
DebugTraceOptionsEnumerates values returned by the Debug.TraceCountAllocs, DebugTraceOptions.CountAllocs, and DebugTraceOptions.None members and taken as a parameter of the Debug.StartMethodTracing member.
DropBoxManagerEnqueues chunks of data (from various sources -- application crashes, kernel log records, etc.
DropBoxManager+EntryA single entry retrieved from the drop box.
DropBoxManager+Entry+InterfaceConsts
DropBoxManagerFlagsEnumerates values returned by several types and taken as a parameter of several types.
EnvironmentProvides access to environment variables.
FileObserverMonitors files (using ) to fire an event after files are accessed or changed by by any process on the device (including this one).
FileObserverEventsEnumerates values returned by several methods of FileObserverEvents and taken as a parameter of the Android.OS.FileObserver..ctor, and FileObserver.OnEvent members.
HandlerA Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue.
Handler+ICallbackCallback interface you can use when instantiating a Handler to avoid having to implement your own subclass of Handler.
HandlerThreadHandy class for starting a new thread that has a looper.
IBinderBase interface for a remotable object, the core part of a lightweight remote procedure call mechanism designed for high performance when performing in-process and cross-process calls.
IBinderDeathRecipientInterface for receiving a callback when the process hosting an IBinder has gone away.
IInterfaceBase class for Binder interfaces.
IParcelableInterface for classes whose instances can be written to and restored from a Parcel.
IParcelableClassLoaderCreatorSpecialization of IParcelableCreator that allows you to receive the ClassLoader the object is being created in.
IParcelableCreatorInterface that must be implemented and provided as a public CREATOR field that generates instances of your Parcelable class from a Parcel.
LooperClass used to run a message loop for a thread.
MemoryFileMemoryFile is a wrapper for the Linux ashmem driver.
MessageDefines a message containing a description and arbitrary data object that can be sent to a Handler.
Message+InterfaceConsts
MessageQueueLow-level class holding the list of messages to be dispatched by a Looper.
MessageQueue+IIdleHandlerCallback interface for discovering when a thread is going to block waiting for more messages.
MessengerReference to a Handler, which others can use to send messages to it.
Messenger+InterfaceConsts
NetworkOnMainThreadExceptionThe exception that is thrown when an application attempts to perform a networking operation on its main thread.
OperationCanceledExceptionAn exception type that is thrown when an operation in progress is canceled.
ParcelContainer for a message (data and object references) that can be sent through an IBinder.
ParcelableInterface for classes whose instances can be written to and restored from a Parcel.
ParcelableConsts
ParcelableWriteFlagsEnumerates values returned by several types and taken as a parameter of several types.
ParcelFileDescriptorThe FileDescriptor returned by Parcel.ReadFileDescriptor, allowing you to close it when done with it.
ParcelFileDescriptor+AutoCloseInputStreamAn InputStream you can create on a ParcelFileDescriptor, which will take care of calling ParcelFileDescriptor.Close for you when the stream is closed.
ParcelFileDescriptor+AutoCloseOutputStreamAn OutputStream you can create on a ParcelFileDescriptor, which will take care of calling ParcelFileDescriptor.Close for you when the stream is closed.
ParcelFileDescriptor+CloseEventArgs
ParcelFileDescriptor+FileDescriptorDetachedException
ParcelFileDescriptor+InterfaceConsts
ParcelFileDescriptor+IOnCloseListener
ParcelFileModeEnumerates values returned by several types and taken as a parameter of the ParcelFileDescriptor.Open, and ParcelFileDescriptor.Open members.
ParcelFormatExceptionThe contents of a Parcel (usually during unmarshalling) does not contain the expected data.
ParcelUuidThis class is a Parcelable wrapper around UUID which is an immutable representation of a 128-bit universally unique identifier.
ParcelUuid+InterfaceConsts
PatternEnumerates values returned by several types and taken as a parameter of several types.
PatternMatcherA simple pattern matcher, which is safe to use on untrusted data: it does not provide full reg-exp support, only simple globbing that can not be used maliciously.
PatternMatcher+InterfaceConsts
PersistableBundleA mapping from String values to various types that can be saved to persistent and later restored.
PersistableBundle+InterfaceConsts
PowerManagerThis class gives you control of the power state of the device.
PowerManager+WakeLockA wake lock is a mechanism to indicate that your application needs to have the device stay on.
ProcessTools for managing OS processes.
RecoverySystemRecoverySystem contains methods for interacting with the Android recovery system (the separate partition that can be used to install system updates, wipe user data, etc.
RecoverySystem+IProgressListenerInterface definition for a callback to be invoked regularly as verification proceeds.
RecoverySystem+ProgressEventArgs
RemoteCallbackListTakes care of the grunt work of maintaining a list of remote interfaces, typically for the use of performing callbacks from a Service to its clients.
RemoteExceptionParent exception for all Binder remote-invocation errors
ResultReceiverGeneric interface for receiving a callback result from someone.
ResultReceiver+InterfaceConsts
SignalEnumerates values returned by the Signal.Kill, Signal.Quit, and Signal.Usr1 members and taken as a parameter of the Process.SendSignal member.
StatFsRetrieve overall information about the space on a filesystem.
StrictMode
StrictMode+ThreadPolicy StrictMode policy applied to a certain thread.
StrictMode+ThreadPolicy+BuilderCreates StrictMode+ThreadPolicy instances.
StrictMode+VmPolicy StrictMode policy applied to all threads in the virtual machine's process.
StrictMode+VmPolicy+BuilderCreates StrictMode+VmPolicy instances.
SystemClockCore timekeeping facilities.
ThreadPriorityEnumerates values returned by several types and taken as a parameter of the Process.SetThreadPriority, and Process.SetThreadPriority members.
TokenWatcherHelper class that helps you use IBinder objects as reference counted tokens.
TraceWrites trace events to the system trace buffer.
TransactionFlagsEnumerates values returned by several types and taken as a parameter of the Binder.Transact, and IBinder.Transact members.
TransactionTooLargeExceptionThe Binder transaction failed because it was too large.
UserHandleRepresentation of a user on the device.
UserHandle+InterfaceConsts
UserManagerManages users and user details on a multi-user system.
VibratorClass that operates the vibrator on the device.
WakeLockFlagsEnumerates values returned by several methods of WakeLockFlags and taken as a parameter of the MediaPlayer.SetWakeMode, PowerManager+WakeLock.Release, and PowerManager.NewWakeLock members.
WorkSourceDescribes the source of some work that may be done by someone else.
WorkSource+InterfaceConsts