Skip to main content
Question

OnbackPressed for Paywalls on Android

  • January 29, 2024
  • 1 reply
  • 120 views

Forum|alt.badge.img+4

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.

This post has been closed for comments

1 reply

Forum|alt.badge.img+3
  • RevenueCat Staff
  • 58 replies
  • January 30, 2024

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.

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings