Android APIs
public class

ActivityOptions

extends Object
java.lang.Object
   ↳ android.app.ActivityOptions

Class Overview

Helper class for building an options Bundle that can be used with Context.startActivity(Intent, Bundle) and related methods.

Summary

Public Methods
static ActivityOptions makeCustomAnimation(Context context, int enterResId, int exitResId)
Create an ActivityOptions specifying a custom animation to run when the activity is displayed.
static ActivityOptions makeScaleUpAnimation(View source, int startX, int startY, int startWidth, int startHeight)
Create an ActivityOptions specifying an animation where the new activity is scaled from a small originating area of the screen to its final full representation.
static ActivityOptions makeSceneTransitionAnimation(Activity activity, Pair...<ViewString> sharedElements)
Create an ActivityOptions to transition between Activities using cross-Activity scene animations.
static ActivityOptions makeSceneTransitionAnimation(Activity activity, View sharedElement, String sharedElementName)
Create an ActivityOptions to transition between Activities using cross-Activity scene animations.
static ActivityOptions makeThumbnailScaleUpAnimation(View source, Bitmap thumbnail, int startX, int startY)
Create an ActivityOptions specifying an animation where a thumbnail is scaled from a given position to the new activity window that is being started.
Bundle toBundle()
Returns the created options as a Bundle, which can be passed to Context.startActivity(Intent, Bundle) and related methods.
void update(ActivityOptions otherOptions)
Update the current values in this ActivityOptions from those supplied in otherOptions.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static ActivityOptions makeCustomAnimation (Context context, int enterResId, int exitResId)

Added in API level 16

Create an ActivityOptions specifying a custom animation to run when the activity is displayed.

Parameters
context Who is defining this. This is the application that the animation resources will be loaded from.
enterResId A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.
exitResId A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.
Returns
  • Returns a new ActivityOptions object that you can use to supply these options as the options Bundle when starting an activity.

public static ActivityOptions makeScaleUpAnimation (View source, int startX, int startY, int startWidth, int startHeight)

Added in API level 16

Create an ActivityOptions specifying an animation where the new activity is scaled from a small originating area of the screen to its final full representation.

If the Intent this is being used with has not set its Intent.setSourceBounds, those bounds will be filled in for you based on the initial bounds passed in here.

Parameters
source The View that the new activity is animating from. This defines the coordinate space for startX and startY.
startX The x starting location of the new activity, relative to source.
startY The y starting location of the activity, relative to source.
startWidth The initial width of the new activity.
startHeight The initial height of the new activity.
Returns
  • Returns a new ActivityOptions object that you can use to supply these options as the options Bundle when starting an activity.

public static ActivityOptions makeSceneTransitionAnimation (Activity activity, Pair...<ViewString> sharedElements)

Create an ActivityOptions to transition between Activities using cross-Activity scene animations. This method carries the position of multiple shared elements to the started Activity. The position of the first element in sharedElements will be used as the epicenter for the exit Transition. The position of the associated shared element in the launched Activity will be the epicenter of its entering Transition.

This requires FEATURE_CONTENT_TRANSITIONS to be enabled on the calling Activity to cause an exit transition. The same must be in the called Activity to get an entering transition.

Parameters
activity The Activity whose window contains the shared elements.
sharedElements The names of the shared elements to transfer to the called Activity and their associated Views. The Views must each have a unique shared element name.
Returns
  • Returns a new ActivityOptions object that you can use to supply these options as the options Bundle when starting an activity. Returns null if the Window does not have FEATURE_CONTENT_TRANSITIONS.

public static ActivityOptions makeSceneTransitionAnimation (Activity activity, View sharedElement, String sharedElementName)

Create an ActivityOptions to transition between Activities using cross-Activity scene animations. This method carries the position of one shared element to the started Activity. The position of sharedElement will be used as the epicenter for the exit Transition. The position of the shared element in the launched Activity will be the epicenter of its entering Transition.

This requires FEATURE_CONTENT_TRANSITIONS to be enabled on the calling Activity to cause an exit transition. The same must be in the called Activity to get an entering transition.

Parameters
activity The Activity whose window contains the shared elements.
sharedElement The View to transition to the started Activity. sharedElement must have a non-null sharedElementName.
sharedElementName The shared element name as used in the target Activity. This may be null if it has the same name as sharedElement.
Returns
  • Returns a new ActivityOptions object that you can use to supply these options as the options Bundle when starting an activity.

public static ActivityOptions makeThumbnailScaleUpAnimation (View source, Bitmap thumbnail, int startX, int startY)

Added in API level 16

Create an ActivityOptions specifying an animation where a thumbnail is scaled from a given position to the new activity window that is being started.

If the Intent this is being used with has not set its Intent.setSourceBounds, those bounds will be filled in for you based on the initial thumbnail location and size provided here.

Parameters
source The View that this thumbnail is animating from. This defines the coordinate space for startX and startY.
thumbnail The bitmap that will be shown as the initial thumbnail of the animation.
startX The x starting location of the bitmap, relative to source.
startY The y starting location of the bitmap, relative to source.
Returns
  • Returns a new ActivityOptions object that you can use to supply these options as the options Bundle when starting an activity.

public Bundle toBundle ()

Added in API level 16

Returns the created options as a Bundle, which can be passed to Context.startActivity(Intent, Bundle) and related methods. Note that the returned Bundle is still owned by the ActivityOptions object; you must not modify it, but can supply it to the startActivity methods that take an options Bundle.

public void update (ActivityOptions otherOptions)

Added in API level 16

Update the current values in this ActivityOptions from those supplied in otherOptions. Any values defined in otherOptions replace those in the base options.