superwall / Superwall-Flutter

Remotely configure every aspect of your paywall and double your revenue.
MIT License
12 stars 6 forks source link

[Android] Faulty state management when moving app to the background #23

Open jaceknijaki opened 3 weeks ago

jaceknijaki commented 3 weeks ago

Disclaimer: This was tested on Android 10, SDK v1.2.1

When paywall is shown and app is moved to the background there are inconsistencies between notifications received by SuperwallDelegate, PaywallPresentationHandler and real Activity state

Attaching logs from the official example app, with my comments:

  1. "Register event" button was pressed in the app
    I/flutter (25928): willPresentPaywall: Instance of 'PaywallInfo'
    I/flutter (25928): didPresentPaywall: Instance of 'PaywallInfo'
    I/flutter (25928): Status: INACTIVE
    I/flutter (25928): Handler (onPresent): Video - 3 options - Discounted (Copy)
  2. Paywall is shown, so far, so good
  3. Moving app to the background (e.g. using system "Home" key)
    I/flutter (25928): willDismissPaywall (reason: PaywallCloseReason.none): Instance of 'PaywallInfo'
    I/flutter (25928): didDismissPaywall (reason: PaywallCloseReason.none): Instance of 'PaywallInfo'
    I/flutter (25928): Handler (onDismiss reason: PaywallCloseReason.none): Video - 3 options - Discounted (Copy)
  4. App in the background - Problem 1: Paywall is not really dismissed, it will be back when app is moved to the foreground
  5. Moving app to the foreground using taks manager
    I/flutter (25928): willPresentPaywall: Instance of 'PaywallInfo'
    I/flutter (25928): didPresentPaywall: Instance of 'PaywallInfo'
    I/flutter (25928): Status: INACTIVE
  6. App in the FG - paywall visible Problem 2: dismiss event was previously sent, but paywall "is back" Problem 3: PaywallPresentationHandler.onPresent() was not called but SuperwallDelegate.didPresentPaywall() was
  7. Moving app to the background again
    I/flutter (25928): willDismissPaywall (reason: PaywallCloseReason.none): Instance of 'PaywallInfo'
    I/flutter (25928): didDismissPaywall (reason: PaywallCloseReason.none): Instance of 'PaywallInfo'
  8. App in the BG (paywall will be back, same as previously) Problem 4: PaywallPresentationHandler.onDismiss() was not invoke, it will be never invoked again, even if using "x" button on the paywall (when app will be back from BG) Problem 5: PaywallCloseReason.none is always sent in the paywallInfo no matter what was the real reason
ianrumac commented 3 weeks ago

Thanks for such detailed report @jaceknijaki !

Regarding step #4 - The PaywallCloseReason.none indicates that the paywall hasn't been closed. I understand this might be confusing tho and I see that we don't have comments in our Flutter code that explain that like we have on native so will definitely add these in.

Regarding step #7 - PaywallPresentationHandler.onPresent() is related to the paywall presentation itself and it should be invoked only when the paywall is presented, while the SuperwallDelegate.didPresentPaywall() is related to the paywall view itself so it can trigger multiple times (i.e. when it shows again)

The step #9 seems like a bug in our native SDK. I'll investigate it further and let you know as soon as the fix is out!

ianrumac commented 2 weeks ago

Hey @jaceknijaki , the issues you've been seeing in step #9 should be resolved now in the version 1.2.2 of the SDK!