public abstract class

Action

extends Object
java.lang.Object
   ↳ com.urbanairship.actions.Action
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

The base action class that describes an operation to perform.

An action is an abstraction over a unary function, which takes ActionArguments and performs a defined task, producing an optional ActionResult. Actions may restrict or vary the work they perform depending on the arguments they receive, which may include type introspection and runtime context.

In the larger view, the Actions framework provides a convenient way to automatically perform tasks by name in response to push notifications, Rich App Page interactions and JavaScript.

The UA library comes with pre-made actions for common tasks such as setting tags and opening URLs out of the box, but this class can also be extended to enable custom app behaviors and engagement experiences.

While actions can be run manually, typically they are associated with names in the ActionRegistry, and run on their own threads with the ActionRunRequest.

Actions that are either long lived or are unable to be interrupted by the device going to sleep should request a wake lock before performing. This is especially important for actions that are performing in SITUATION_PUSH_RECEIVED, when a push is delivered when the device is not active.

The value returned by shouldRunOnMainThread() determines which thread should run the action if executed asynchronously. If an action involves a UI interaction, this method should be overridden to return true so that the action definitely runs before the app state changes.

Summary

Nested Classes
@interface Action.Situation  
Constants
int SITUATION_AUTOMATION Situation where an action is triggered from Automation.
int SITUATION_BACKGROUND_NOTIFICATION_ACTION_BUTTON Situation where an action is triggered from a background notification action button.
int SITUATION_FOREGROUND_NOTIFICATION_ACTION_BUTTON Situation where an action is triggered from a foreground notification action button.
int SITUATION_MANUAL_INVOCATION Situation where an action is manually invoked.
int SITUATION_PUSH_OPENED Situation where an action is triggered when a push is opened.
int SITUATION_PUSH_RECEIVED Situation where an action is triggered when a push is received.
int SITUATION_WEB_VIEW_INVOCATION Situation where an action is triggered from a web view.
Public Constructors
Action()
Public Methods
boolean acceptsArguments(ActionArguments arguments)
Called before an action is performed to determine if the the action can accept the arguments.
void onFinish(ActionArguments arguments, ActionResult result)
Called after the action performs.
void onStart(ActionArguments arguments)
Called before an action is performed.
abstract ActionResult perform(ActionArguments arguments)
Performs the action.
boolean shouldRunOnMainThread()
Determines which thread runs the action.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int SITUATION_AUTOMATION

Situation where an action is triggered from Automation.

Constant Value: 6 (0x00000006)

public static final int SITUATION_BACKGROUND_NOTIFICATION_ACTION_BUTTON

Situation where an action is triggered from a background notification action button.

Constant Value: 5 (0x00000005)

public static final int SITUATION_FOREGROUND_NOTIFICATION_ACTION_BUTTON

Situation where an action is triggered from a foreground notification action button.

Constant Value: 4 (0x00000004)

public static final int SITUATION_MANUAL_INVOCATION

Situation where an action is manually invoked.

Constant Value: 0 (0x00000000)

public static final int SITUATION_PUSH_OPENED

Situation where an action is triggered when a push is opened.

Constant Value: 2 (0x00000002)

public static final int SITUATION_PUSH_RECEIVED

Situation where an action is triggered when a push is received.

Constant Value: 1 (0x00000001)

public static final int SITUATION_WEB_VIEW_INVOCATION

Situation where an action is triggered from a web view.

Constant Value: 3 (0x00000003)

Public Constructors

public Action ()

Public Methods

public boolean acceptsArguments (ActionArguments arguments)

Called before an action is performed to determine if the the action can accept the arguments.

Parameters
arguments The action arguments.
Returns
  • true if the action can perform with the arguments, otherwise false.

public void onFinish (ActionArguments arguments, ActionResult result)

Called after the action performs.

Parameters
arguments The action arguments.
result The result of the action.

public void onStart (ActionArguments arguments)

Called before an action is performed.

Parameters
arguments The action arguments.

public abstract ActionResult perform (ActionArguments arguments)

Performs the action.

Parameters
arguments The action arguments.
Returns
  • The result of the action.

public boolean shouldRunOnMainThread ()

Determines which thread runs the action.

Returns
  • true if the action should be run on the main thread, or false if the action should run on a background thread.