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:
- Adapty Android SDK v4 or later: Earlier versions can’t render flows. To move an existing app from v3, see the migration guide.
observerModeset totrue: See the Android SDK installation guide.- Initial store integration: Set up Adapty with Google Play.
- A published flow with products: Build it in the Flow & Paywall Builder and assign products to it.
- A flow placement: Create a placement and assign your flow to it.
- The flow fetched in your app: Get the flow and its configuration before you present it.
Implementation
- 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:
| Callback | Description |
|---|---|
| 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. |
- In order to display the visual flow on the device screen, you must first configure it.
Request parameters:
| Parameter | Presence | Description |
|---|---|---|
| flowConfiguration | required | Supply 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. |
| products | optional | Provide 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. |
| eventListener | optional | Provide an AdaptyFlowEventListener to observe flow events. Extending AdaptyFlowDefaultEventListener is recommended for ease of use. Refer to Handle flow & paywall events topic for more details. |
| insets | optional | Insets 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. |
| customAssets | optional | Pass an AdaptyCustomAssets object to replace images and videos in your flow at runtime. Refer to Customize assets for more details. |
| tagResolver | optional | Use AdaptyUiTagResolver to resolve custom tags within the flow text. This resolver takes a tag parameter and resolves it to a corresponding string. |
| observerModeHandler | required for Observer mode | The AdaptyUiObserverModeHandler you’ve implemented in the previous step. |
Don’t forget to associate paywalls to purchase transactions. Otherwise, Adapty will not determine the source flow of the purchase.