Present flows in Observer mode in Android SDK

If you use Observer mode, you are responsible for your own purchase logic. But you can delegate the paywall UI to the Flow & Paywall Builder.

Design the screen in the builder, and the Adapty SDK renders it natively. Update its copy, layout, and pricing whenever you want, without an app release. When a user taps a purchase button, the SDK calls your code to complete the purchase.

This guide shows how to present that screen and handle the purchase call. If Adapty completes purchases for you, see Display flows & paywalls instead.

Before you start

You need:

Implementation

  1. Implement the AdaptyUiObserverModeHandler.

The onPurchaseInitiated event will inform you that the user has initiated a purchase. You can trigger your custom purchase flow in response to this callback:

To handle restores in Observer mode, override getRestoreHandler(). By default it returns null, which uses Adapty’s built-in Adapty.restorePurchases() flow. To provide your own restore implementation:

Remember to invoke the following callbacks to notify AdaptyUI about the purchase or restore process. This is necessary for proper flow behavior, such as showing the loader:

CallbackDescription
onStartPurchase()The callback should be invoked to notify AdaptyUI that the purchase is started.
onFinishPurchase()The callback should be invoked to notify AdaptyUI that the purchase is finished.
onStartRestore()Optional. The callback can be invoked to notify AdaptyUI that the restore is started.
onFinishRestore()Optional. The callback can be invoked to notify AdaptyUI that the restore is finished.
  1. In order to display the visual flow on the device screen, you must first configure it.

Request parameters:

ParameterPresenceDescription
flowConfigurationrequiredSupply an AdaptyUI.FlowConfiguration object containing visual details of the flow. Use the AdaptyUI.getFlowConfiguration(flow) method to load it. Refer to Fetch the view configuration topic for more details.
productsoptionalProvide an array of AdaptyPaywallProduct to optimize the display timing of products on the screen. If null is passed, AdaptyUI will automatically fetch the required products.
eventListeneroptionalProvide an AdaptyFlowEventListener to observe flow events. Extending AdaptyFlowDefaultEventListener is recommended for ease of use. Refer to Handle flow & paywall events topic for more details.
insetsoptionalInsets are the spaces around the flow that prevent tapable elements from getting hidden behind system bars. Default: Unspecified, which lets Adapty adjust the insets automatically. See Change flow insets.
customAssetsoptionalPass an AdaptyCustomAssets object to replace images and videos in your flow at runtime. Refer to Customize assets for more details.
tagResolveroptionalUse AdaptyUiTagResolver to resolve custom tags within the flow text. This resolver takes a tag parameter and resolves it to a corresponding string.
observerModeHandlerrequired for Observer modeThe AdaptyUiObserverModeHandler you’ve implemented in the previous step.
Warning

Don’t forget to associate paywalls to purchase transactions. Otherwise, Adapty will not determine the source flow of the purchase.