Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29432

Reload AdMob Rewarded Ad without rebuilding App in React Native

$
0
0

I have created a Button to display a rewarded Ad whenever it gets clicked.There are two issues now:1. It takes too much time to load the Ad (I can click the button once or twice before anything happens).2. I want to reload the Ad right after it closes. It works but the App needs to restart.

AdMobRewardedComponent.js

  async componentDidMount() {  await setTestDeviceIDAsync("EMULATOR");  AdMobRewarded.setAdUnitID("ca-app-pub-3940256099942544/5224354917");  AdMobRewarded.addEventListener("rewardedVideoDidLoad", () => {  console.log("VideoLoaded")  });  AdMobRewarded.addEventListener("rewardedVideoDidFailToLoad", () =>  console.log("FailedToLoad")  );  AdMobRewarded.addEventListener("rewardedVideoDidOpen", () =>  console.log("Opened")  );  AdMobRewarded.addEventListener("rewardedVideoDidClose", () => {    loadAd(request.build());  console.log("Closed")  });  AdMobRewarded.addEventListener("rewardedVideoWillLeaveApplication", () =>  console.log("LeaveApp")  );  AdMobRewarded.addEventListener("rewardedVideoDidStart", () =>  console.log("Started")  );  AdMobRewarded.addEventListener("rewardedVideoDidRewardUser", () =>  console.log("Rewarded"),  );  await AdMobRewarded.requestAdAsync();}componentWillUnmount() {  AdMobRewarded.removeAllListeners();}_handlePress = async () => {  await AdMobRewarded.showAdAsync();};render() {  const { loadedAd } = this.state;  return (<TouchableButton onPress={this._handlePress} title="Coins erhalten!" image="adButton" status="active" style={styles.adButton}/>    );  }};

Is there a way to request a new Ad without restarting the whole App?Thanks for every answer!


Viewing all articles
Browse latest Browse all 29432

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>