AppLovin / AppLovin-MAX-React-Native

MIT License
55 stars 29 forks source link

showRewardedAd() blocks further code execution after the ad starts showing #120

Closed tabowillow closed 1 year ago

tabowillow commented 1 year ago

MAX Module Version

4.0.0

React Native Version

0.70.1

Device/Platform Info

The problem appears on all physical devices and emulators

Current Behavior

While the ad is showing, it is planned to poll the server (processing user input). But polling stops when ad is shown. This happens exactly at the moment the ad is shown, and not when the showRewardedAd() is called, because one request has time to pass. An attempt to wrap a showRewardedAd() call in a promise doesn't work.

Expected Behavior

While the ad is showing, the rest of the app doesn't stop.

How to Reproduce

I have a function that starts the polling process and shows the ad right after it:

const handlePollingStart = async () => {
  const processor = new Processor() // polling processor
  processor.start().then().catch()
  AppLovinMAX.showRewardedAd(AD_UNIT_ID)
}

I also tried wrapping the showRewardedAd() call in a Promise, that doesn't work either:

const showAd = () => new Promise(() => AppLovinMAX.showRewardedAd(AD_UNIT_ID))

const handlePollingStart = async () => {
  const processor = new Processor() // polling processor
  processor.start().then().catch()
  showAd().then().catch()
}

Additional Info

No response

alhiwatan commented 1 year ago

Rewarded / Interstitial ads are implemented to start an activity on top of the current activity in Android to show full-screen ads. You can verify that with the Layout Inspector in Android Studio. When that happens, the current activity is paused and stopped. That is why your networking is stopped and resumed when the ad is closed. This is standard Android behavior in React Native.

In order to avoid the situation, I guess that you can use Headless JS or 3rd party libraries that allow running things in the background.

alhiwatan commented 1 year ago

Will close as 'not a bug'. Feel free to reopen if this needs to be addressed further.