public final class

RequestContext

extends Object
java.lang.Object
   ↳ com.amazon.identity.auth.device.api.workflow.RequestContext

Class Overview

In order to support out-of-app interactive user experiences while accommodating for the Android application lifecycle, the Login With Amazon SDK provides RequestContext. It serves as a tie between the interactive requests and listeners registered to handle their responses.

Using an interactive flow (such as authorization) requires the RequestContext to be integrated correctly. The following describes the integration for a single interactive request source, which is the fragment or activity that your interactive request originates from:

  1. Declare a RequestContext instance variable in the originating fragment or activity.
  2. Assign the RequestContext to create(Activity), passing in your activity or fragment.
  3. Register all listeners for requests that will be made from your fragment or activity in the onCreate (or onCreateView if your listener will capture references to views).
  4. Override your fragment or activity's onResume and call onResume() within it.
{@since 3.0 }

Summary

Public Methods
void assertListenerPresent(InteractiveAPI api)
This API is intended only for use by Login With Amazon-enabled SDKs.
static RequestContext create(FragmentActivity activity)
Factory method for android.support.v4.app.FragmentActivity request sources.
static RequestContext create(Context context)
Factory method for Context request sources.
static RequestContext create(Activity activity)
Factory method for Activity request sources.
static RequestContext create(Fragment fragment)
Factory method for android.support.v4.app.Fragment request sources.
static RequestContext create(Fragment fragment)
Factory method for Fragment request sources.
<T extends InteractiveListener<S, U, V>, S, U, V> InteractiveListener<S, U, V> getAggregateListener(InteractiveRequest<T, S, U, V> request)
This API is intended only for use by Login With Amazon-enabled SDKs.
Context getContext()
<T> Set<T> getListeners(InteractiveAPI api, Class<T> listenerClass)
This API is intended only for use by Login With Amazon-enabled SDKs.
boolean isHookNeededOnUIResume()
This API is intended only for use by Login With Amazon-enabled SDKs.
void onResume()
Override the onResume of your activity or fragment and call this method within it.
void onStartRequest(InteractiveRequestRecord request)
Do not call this API, it is used internally by the SDK and may be subject to change without notice.
void processResponse(InteractiveRequestRecord request, Uri uri)
Do not call this API, it is used internally by the SDK and may be subject to change without notice.
void registerListener(InteractiveListener<?, ?, ?> listener)
Adds the listener to the set of listeners that this request context can handle.
boolean unregisterListener(InteractiveListener<?, ?, ?> listener)
Removes a listener instance from the set of listeners this request can handle.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void assertListenerPresent (InteractiveAPI api)

This API is intended only for use by Login With Amazon-enabled SDKs.

This method throws a runtime exception if a given interactive API (such as InteractiveRequest or InteractiveListener) has a corresponding listener present in the set of listeners. The exception should be propagated to the application developer to indicate an invalid integration.

This is implicitly called when openWorkflow(InteractiveRequest, String, String, Bundle) is called to ensure that there is a listener for a given interactive request. Before calling openWorkflow, it is useful for Login With Amazon-enabled SDKs to call this method before attempting to access the listeners in the case of fail-fast or short-circuit scenarios.

Parameters
api A request or listener object that corresponds to the type of listener whose presence is being asserted.
Throws
ListenerNotFoundException If a corresponding listener for the given api is not available in the set of listeners maintained by this request context.

public static RequestContext create (FragmentActivity activity)

Factory method for android.support.v4.app.FragmentActivity request sources.

Your app must use the Android Support Library v4 in order to use this API.

This API is deprecated, please refer to create(Context)

Parameters
activity The source of your interactive request.
Returns
  • The request context associated with the given request source.

public static RequestContext create (Context context)

Factory method for Context request sources.

Your app must use the Android Support Library v4 in order to use this API.

Parameters
context The context source of your interactive request.
Returns
  • The request context associated with the given request source.

public static RequestContext create (Activity activity)

Factory method for Activity request sources.

This API is deprecated, please refer to create(Context)

Parameters
activity The source of your interactive request.
Returns
  • The request context associated with the given request source.

public static RequestContext create (Fragment fragment)

Factory method for android.support.v4.app.Fragment request sources.

Your app must use the Android Support Library v4 in order to use this API.

Parameters
fragment The source of your interactive request.
Returns
  • The request context associated with the given request source.

public static RequestContext create (Fragment fragment)

Factory method for Fragment request sources.

Your app must declare minSdkVersoin >= 11 in order to use this API.

Parameters
fragment The source of your interactive request.
Returns
  • The request context associated with the given request source.

public InteractiveListener<S, U, V> getAggregateListener (InteractiveRequest<T, S, U, V> request)

This API is intended only for use by Login With Amazon-enabled SDKs.

As an app developer may register multiple listeners for any given type of interactive request, this method exposes a listener that is the aggregation of all listeners of a given type for convenience. The aggregated listeners will be executed in an undefined order.

Parameters
request The request with which it should retrieve the aggregate listener for.
Returns
  • A listener that is an aggregation of all listeners registered with this context for the given interactive request.
Throws
ListenerNotFoundException If no listeners were present for the given request.

public Context getContext ()

Returns
  • The Android Context that the request context is associated with.

public Set<T> getListeners (InteractiveAPI api, Class<T> listenerClass)

This API is intended only for use by Login With Amazon-enabled SDKs.

Retrieves the set of listeners registered for a given interactive API, cast to a the given listenerClass.

Parameters
api The interactive API to get the listeners for.
listenerClass The Class of listener that the listener should be cast to.
Returns
  • A listener that is an aggregation of all listeners registered with this context for the given interactive request.

public boolean isHookNeededOnUIResume ()

This API is intended only for use by Login With Amazon-enabled SDKs.

Do not call this API, it is used internally by the SDK and may be subject to change without notice. Indicate if the RequestContext needed to be hooked at host Activity/Fragment.

public void onResume ()

Override the onResume of your activity or fragment and call this method within it.

This signals to the RequestContext that it should execute listeners for interactive flows that have finished. The listeners will be executed on a separate thread.

public void onStartRequest (InteractiveRequestRecord request)

Do not call this API, it is used internally by the SDK and may be subject to change without notice.

This method notifies the request context that a given request has been started.

Parameters
request A record of the request being started.

public void processResponse (InteractiveRequestRecord request, Uri uri)

Do not call this API, it is used internally by the SDK and may be subject to change without notice.

Executes all listeners for a given interactive response URI on a separate thread pool.

Parameters
request A record of the request whose response is getting handled.
uri The completed interactive response as a URI.

public void registerListener (InteractiveListener<?, ?, ?> listener)

Adds the listener to the set of listeners that this request context can handle. This must be done in one of the Android "on create" lifecycle methods to ensure that the listeners are available if your activity or fragment is recreated.

Parameters
listener The callback for a request that the originating request source will make.

public boolean unregisterListener (InteractiveListener<?, ?, ?> listener)

Removes a listener instance from the set of listeners this request can handle. Because listeners are anonymous, the same instance must be passed in for it to be removed.

Parameters
listener The same listener instance to be removed.
Returns
  • true if the specified listener was removed, false otherwise.