SystemClock Class

Definition

Core timekeeping facilities.

[Android.Runtime.Register("android/os/SystemClock", DoNotGenerateAcw=true)]
public sealed class SystemClock : Java.Lang.Object
[<Android.Runtime.Register("android/os/SystemClock", DoNotGenerateAcw=true)>]
type SystemClock = class
    inherit Object
Inheritance
SystemClock
Attributes

Remarks

Core timekeeping facilities.

Three different clocks are available, and they should not be confused:

<ul> <li>

System#currentTimeMillis System.currentTimeMillis() is the standard "wall" clock (time and date) expressing milliseconds since the epoch. The wall clock can be set by the user or the phone network (see #setCurrentTimeMillis), so the time may jump backwards or forwards unpredictably. This clock should only be used when correspondence with real-world dates and times is important, such as in a calendar or alarm clock application. Interval or elapsed time measurements should use a different clock. If you are using System.currentTimeMillis(), consider listening to the android.content.Intent#ACTION_TIME_TICK ACTION_TIME_TICK, android.content.Intent#ACTION_TIME_CHANGED ACTION_TIME_CHANGED and android.content.Intent#ACTION_TIMEZONE_CHANGED ACTION_TIMEZONE_CHANGEDandroid.content.Intent Intent broadcasts to find out when the time changes.

<li>

#uptimeMillis is counted in milliseconds since the system was booted. This clock stops when the system enters deep sleep (CPU off, display dark, device waiting for external input), but is not affected by clock scaling, idle, or other power saving mechanisms. This is the basis for most interval timing such as Thread#sleep(long) Thread.sleep(millis), Object#wait(long) Object.wait(millis), and System#nanoTime System.nanoTime(). This clock is guaranteed to be monotonic, and is suitable for interval timing when the interval does not span device sleep. Most methods that accept a timestamp value currently expect the #uptimeMillis clock.

<li>

#elapsedRealtime and #elapsedRealtimeNanos return the time since the system was booted, and include deep sleep. This clock is guaranteed to be monotonic, and continues to tick even when the CPU is in power saving modes, so is the recommend basis for general purpose interval timing.

</ul>

There are several mechanisms for controlling the timing of events:

<ul> <li>

Standard functions like Thread#sleep(long) Thread.sleep(millis) and Object#wait(long) Object.wait(millis) are always available. These functions use the #uptimeMillis clock; if the device enters sleep, the remainder of the time will be postponed until the device wakes up. These synchronous functions may be interrupted with Thread#interrupt Thread.interrupt(), and you must handle InterruptedException.

<li>

#sleep SystemClock.sleep(millis) is a utility function very similar to Thread#sleep(long) Thread.sleep(millis), but it ignores InterruptedException. Use this function for delays if you do not use Thread#interrupt Thread.interrupt(), as it will preserve the interrupted state of the thread.

<li>

The android.os.Handler class can schedule asynchronous callbacks at an absolute or relative time. Handler objects also use the #uptimeMillis clock, and require an android.os.Looper event loop (normally present in any GUI application).

<li>

The android.app.AlarmManager can trigger one-time or recurring events which occur even when the device is in deep sleep or your application is not running. Events may be scheduled with your choice of java.lang.System#currentTimeMillis (RTC) or #elapsedRealtime (ELAPSED_REALTIME), and cause an android.content.Intent broadcast when they occur. </ul>

Java documentation for android.os.SystemClock.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Name Description
Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode

Gets the identity hash code assigned to this Java peer by the interop runtime.

(Inherited from Object)
JniPeerMembers

Provides JNI peer-member metadata for this type.

PeerReference

Gets the JNI object reference for this Java peer.

(Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)

Methods

Name Description
Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CurrentGnssTimeClock()

Returns a Clock that starts at January 1, 1970 00:00:00.

CurrentNetworkTimeClock()

Returns a Clock that starts at January 1, 1970 00:00:00.

CurrentThreadTimeMillis()

Returns milliseconds running in the current thread.

Dispose()

Releases the resources held by this Java peer.

(Inherited from Object)
Dispose(Boolean)

Releases the resources held by this Java peer.

(Inherited from Object)
ElapsedRealtime()

Returns milliseconds since boot, including time spent in sleep.

ElapsedRealtimeNanos()

Returns nanoseconds since boot, including time spent in sleep.

Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetCurrentTimeMillis(Int64)

Sets the current wall time, in milliseconds.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
Sleep(Int64)

Waits a given number of milliseconds (of uptimeMillis) before returning.

ToArray<T>()

Creates a managed array from this Java array wrapper.

(Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime()

Unregisters this Java peer from the interop runtime.

(Inherited from Object)
UptimeMillis()

Returns milliseconds since boot, not counting time spent in deep sleep.

UptimeNanos()

Returns nanoseconds since boot, not counting time spent in deep sleep.

Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

Name Description
IJavaPeerable.Disposed()

Notifies the interop runtime that this managed peer has been disposed.

(Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced()

Releases this Java peer unless it is retained by another managed reference.

(Inherited from Object)
IJavaPeerable.Finalized()

Notifies the interop runtime that this managed peer has been finalized.

(Inherited from Object)
IJavaPeerable.JniManagedPeerState

Gets the state that describes the relationship between this managed peer and its JNI reference.

(Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32)

Sets the interop identity hash code for this Java peer.

(Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)

Sets the managed and JNI peer state for this Java peer.

(Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference)

Sets the JNI object reference used by this managed peer.

(Inherited from Object)

Extension Methods

Name Description
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to