Skip to main content
Question

Launch Paywall as a fragment Kotlin Android

  • September 7, 2024
  • 1 reply
  • 92 views

Forum|alt.badge.img+1

I’m currently launching Paywall from inside a Fragment like this:

 

class PaywallFragment: Fragment(), PaywallResultHandler, SlidePolicy {

private lateinit var paywallActivityLauncher: PaywallActivityLauncher

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
paywallActivityLauncher = PaywallActivityLauncher(this, this)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
launchPaywall()
return super.onCreateView(inflater, container, savedInstanceState)
}

override fun onResume() {
super.onResume()

}

private fun launchPaywall() {
Purchases.sharedInstance.getOfferings(object : ReceiveOfferingsCallback {
override fun onError(error: PurchasesError) {
Timber.e(error.message)
}

override fun onReceived(offerings: Offerings) {
val currentOffering = offerings.current
currentOffering?.let { offering ->
paywallActivityLauncher.launch(offering)
}
}

})
}

override fun onActivityResult(result: PaywallResult) {
}

override val isPolicyRespected: Boolean get() = true

override fun onUserIllegallyRequestedNextPage() {
//
}

companion object {
fun newInstance(): PaywallFragment {
return PaywallFragment()
}
}
}

 

The problem is - this is launching an activity from inside a Fragment. I want to show this paywall as a fragment during the onboarding phase (inside the onboarding activity as one of the slides). I don’t see any support on the SDK to achieve that. Is it possible?

Note that I’m not using Jetpack Compose on my project.

 

This post has been closed for comments

1 reply

kaitlin
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • September 11, 2024

Hi @kaidul-2a1912,

Have you considered using Placements?

This will allow you to show a specific Paywall at specific points in your app flow, such as onboarding. Placements was launched as part of our Targeting feature but I think it would work pretty well for your use case: https://www.revenuecat.com/docs/tools/targeting/placements#supported-in-the-following-sdk-versions

Let us know if you have any questions about this!