Interface ActivityManager

interface ActivityManager {
    getActivityInfo(): ActivityInfo;
    getActivityState(): ActivityState;
    runIn<T>(expectedState: ActivityState, action: AbortableCallback<T>): AbortablePromise<T>;
    runUserInteraction<T>(action: AbortableCallback<T>): AbortablePromise<T>;
    startActivity(intent: Intent): boolean;
    startActivityForResult(intent: Intent): Promise<null | ActivityResult>;
    subscribe(listener: ((activityState: ActivityState) => void)): Unsubscribe;
    subscribe(eventType: "background", listener: (() => void)): Unsubscribe;
    subscribe(eventType: "foreground", listener: (() => void)): Unsubscribe;
    subscribe(eventType: "active", listener: (() => void)): Unsubscribe;
}

Methods

  • Runs the action once the activity is in the expected state.

    If the activity is in the expected state then the action is run immediately. Otherwise, the expected state is awaited and then the action is invoked.

    Type Parameters

    • T

      The result returned by the action.

    Parameters

    Returns AbortablePromise<T>

    The promise to the action result.

  • Runs an action that blocks the UI.

    If the activity is in the active state then the action is run immediately. Otherwise, the active state is awaited and then the action is invoked. Consequent actions that are run using this method are deferred until the current action is resolved.

    Type Parameters

    • T

      The result returned by the action.

    Parameters

    Returns AbortablePromise<T>

    The promise to the action result.

  • Starts an activity for the intent.

    Parameters

    • intent: Intent

      The intent that starts an activity.

    Returns boolean

    true if activity has started, or false otherwise.

  • Starts an activity for the intent and wait for it to return the result.

    Note: This operation requires the user interaction, consider using ActivityManager.runUserInteraction to ensure that consequent UI-related operations are suspended until this one is completed.

    Parameters

    • intent: Intent

      The intent that starts an activity.

    Returns Promise<null | ActivityResult>

    The activity result.

  • Subscribes a listener to activity status changes.

    Parameters

    Returns Unsubscribe

  • The activity went to background: user doesn't see the activity anymore.

    Parameters

    • eventType: "background"
    • listener: (() => void)
        • (): void
        • Returns void

    Returns Unsubscribe

  • The activity entered foreground: user can see the activity but cannot interact with it.

    Parameters

    • eventType: "foreground"
    • listener: (() => void)
        • (): void
        • Returns void

    Returns Unsubscribe

  • The activity became active: user can see the activity and can interact with it.

    Parameters

    • eventType: "active"
    • listener: (() => void)
        • (): void
        • Returns void

    Returns Unsubscribe