sbugert / react-native-admob

A react-native component for Google AdMob banners
BSD 2-Clause "Simplified" License
1.13k stars 530 forks source link

Android. App closed and works in backgroung after closing interstitial #199

Open Stalder opened 7 years ago

Stalder commented 7 years ago

It works great on Android emulator and IOS, but if i try to close interstitial on android device, app is closing and works in background. If i resume app, it still works great

RN 0.49 expo 21 react-native-admob 1.3.2

There is a snippet:

AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
AdMobInterstitial.setTestDeviceID('EMULATOR');

class AdMob extends Component {

  componentDidMount(){
    const { dispatch } = this.props;
    AdMobInterstitial.addEventListener('interstitialDidClose', () => {
      console.log('CLOSED');
      dispatch(actionCreators.setPage({name: 'Hello'}));
    });
    AdMobInterstitial.requestAd(() => AdMobInterstitial.showAd());
  }

  render() {
    return null
  }
}

export default connect(mapStateToProps)(AdMob)

Full test project is here: https://github.com/Stalder/AdMobTest Expo project: https://exp.host/@stalder/flatlist-test

Stalder commented 7 years ago

Tried to migrate to react-native-admob 2.0.0-beta.2, the same issue. + now doesn't work eventListener which subscribed to adClosed

componentDidMount(){
    const { dispatch } = this.props;
    AdMobInterstitial.addEventListener('adClosed', () => {
      console.log('CLOSED');
      dispatch(actionCreators.setPage({name: 'Hello'}));
    });
    AdMobInterstitial.requestAd(error => {
      AdMobInterstitial.showAd((error) => {});
    });
  }
pixochi commented 6 years ago

Did you resolve the issue? My app is also brought to the background right after the interstitial ad is closed. I initiate it only once in ComponentDidMount of the main component and the ad is requested and shown with this. AdMobInterstitial.requestAd(() => { AdMobInterstitial.showAd(); });

koenpunt commented 6 years ago

@pixochi your comment made me understand what this issue is about, thanks! Will see if there’s something to do.

pixochi commented 6 years ago

@koenpunt I was using it inside Expo when this happened, now I built a standalone android app and the problem is gone. Sorry, I didn't mention expo before, but I didn't realize it would make a difference.