Question

OnbackPressed for Paywalls on Android

  • 29 January 2024
  • 1 reply
  • 56 views

Badge +3

I am implementing Paywalls on kotlin for my Android app, however whenever the user swipes back or presses the back button, the paywall simply goes away and a white screen shows up. For context, I am implementing a hard paywall (without a back button, or option to say no). I wonder how I can override this behavior. I am using version 7.4.0.


1 reply

Userlevel 2
Badge +3

Hi @healthappy-ae08ec, thanks for reaching out!

If you’re using paywalls through compose, you could handle displaying the paywall yourself by adding the appropriate logic in the listeners, like:

var shouldShowPaywall by remember {
mutableStateOf(true)
}
if (shouldShowPaywall) {
Paywall(
PaywallOptions.Builder({ /* Leave empty */ })
.setListener(object : PaywallListener {
override fun onPurchaseCompleted(
customerInfo: CustomerInfo,
storeTransaction: StoreTransaction
) {
if (customerInfo.entitlements.active.containsKey("MY_ENTITLEMENT_ID")) {
shouldShowPaywall = false
}
}

override fun onRestoreCompleted(customerInfo: CustomerInfo) {
if (customerInfo.entitlements.active.containsKey("MY_ENTITLEMENT_ID")) {
shouldShowPaywall = false
}
}
})
.build(),
)
}

If you’re using the `PaywallActivityLauncher` to display the paywall as an activity, we currently don’t support disabling the back button, but we’re considering adding that as a feature request.

 

Reply