Choreographer | API reference | Android Developers (original) (raw)
public final class Choreographerextends [Object](/reference/java/lang/Object) ``
Coordinates the timing of animations, input and drawing.
The choreographer receives timing pulses (such as vertical synchronization) from the display subsystem then schedules work to occur as part of rendering the next display frame.
Applications typically interact with the choreographer indirectly using higher level abstractions in the animation framework or the view hierarchy. Here are some examples of things you can do using the higher-level APIs.
- To post an animation to be processed on a regular time basis synchronized with display frame rendering, use
[ValueAnimator.start()](/reference/android/animation/ValueAnimator#start%28%29). - To post a
[Runnable](/reference/java/lang/Runnable)to be invoked once at the beginning of the next display frame, use[View.postOnAnimation](/reference/android/view/View#postOnAnimation%28java.lang.Runnable%29). - To post a
[Runnable](/reference/java/lang/Runnable)to be invoked once at the beginning of the next display frame after a delay, use[View.postOnAnimationDelayed](/reference/android/view/View#postOnAnimationDelayed%28java.lang.Runnable,%20long%29). - To post a call to
[View.invalidate()](/reference/android/view/View#invalidate%28%29)to occur once at the beginning of the next display frame, use[View.postInvalidateOnAnimation()](/reference/android/view/View#postInvalidateOnAnimation%28%29)or[View.postInvalidateOnAnimation(int,int,int,int)](/reference/android/view/View#postInvalidateOnAnimation%28int,%20int,%20int,%20int%29). - To ensure that the contents of a
[View](/reference/android/view/View)scroll smoothly and are drawn in sync with display frame rendering, do nothing. This already happens automatically.[View.onDraw](/reference/android/view/View#onDraw%28android.graphics.Canvas%29)will be called at the appropriate time.
However, there are a few cases where you might want to use the functions of the choreographer directly in your application. Here are some examples.
- If your application does its rendering in a different thread, possibly using GL, or does not use the animation framework or view hierarchy at all and you want to ensure that it is appropriately synchronized with the display, then use
[Choreographer.postFrameCallback](/reference/android/view/Choreographer#postFrameCallback%28android.view.Choreographer.FrameCallback%29). - ... and that's about it.
Each [Looper](/reference/android/os/Looper) thread has its own choreographer. Other threads can post callbacks to run on the choreographer but they will run on the [Looper](/reference/android/os/Looper) to which the choreographer belongs.
Summary
| Nested classes | |
|---|---|
| interface | Choreographer.FrameCallback Implement this interface to receive a callback when a new display frame is being rendered. |
| class | Choreographer.FrameData The payload for VsyncCallback which includes frame information such as when the frame started being rendered, and multiple possible frame timelines and their information including deadline and expected present time. |
| class | Choreographer.FrameTimeline Holds data that describes one possible VSync frame event to render at. |
| interface | Choreographer.VsyncCallback Implement this interface to receive a callback to start the next frame. |
| Public methods | |
|---|---|
| staticChoreographer | getInstance() Gets the choreographer for the calling thread. |
| void | postFrameCallback(Choreographer.FrameCallback callback) Posts a frame callback to run on the next frame. |
| void | postFrameCallbackDelayed(Choreographer.FrameCallback callback, long delayMillis) Posts a frame callback to run on the next frame after the specified delay. |
| void | postVsyncCallback(Choreographer.VsyncCallback callback) Posts a vsync callback to run on the next frame. |
| void | removeFrameCallback(Choreographer.FrameCallback callback) Removes a previously posted frame callback. |
| void | removeVsyncCallback(Choreographer.VsyncCallback callback) Removes a previously posted vsync callback. |
| Inherited methods |
|---|
| From class java.lang.Object Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. finalClass<?> getClass() Returns the runtime class of this Object. int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
Public methods
getInstance
public static Choreographer getInstance ()
Gets the choreographer for the calling thread. Must be called from a thread that already has a [Looper](/reference/android/os/Looper) associated with it.
| Returns | |
|---|---|
| Choreographer | The choreographer for this thread. |
| Throws | |
|---|---|
| IllegalStateException | if the thread does not have a looper. |
postFrameCallback
public void postFrameCallback (Choreographer.FrameCallback callback)
Posts a frame callback to run on the next frame.
The callback runs once then is automatically removed.
| Parameters | |
|---|---|
| callback | Choreographer.FrameCallback: The frame callback to run during the next frame. |
postFrameCallbackDelayed
public void postFrameCallbackDelayed (Choreographer.FrameCallback callback, long delayMillis)
Posts a frame callback to run on the next frame after the specified delay.
The callback runs once then is automatically removed.
| Parameters | |
|---|---|
| callback | Choreographer.FrameCallback: The frame callback to run during the next frame. |
| delayMillis | long: The delay time in milliseconds. |
postVsyncCallback
public void postVsyncCallback (Choreographer.VsyncCallback callback)
Posts a vsync callback to run on the next frame.
The callback runs once then is automatically removed.
| Parameters | |
|---|---|
| callback | Choreographer.VsyncCallback: The vsync callback to run during the next frame. This value cannot be null. |
removeFrameCallback
public void removeFrameCallback (Choreographer.FrameCallback callback)
Removes a previously posted frame callback.
| Parameters | |
|---|---|
| callback | Choreographer.FrameCallback: The frame callback to remove. |
removeVsyncCallback
public void removeVsyncCallback (Choreographer.VsyncCallback callback)
Removes a previously posted vsync callback.
| Parameters | |
|---|---|
| callback | Choreographer.VsyncCallback: The vsync callback to remove. This value may be null. |