Вопрос

I'm implementing interstitial banners on this Android app and wish them to appear when user finish()es the app through back button. It's already working fine when using solo AdMob interstitial by AdMob mediation, this way:

@Override
public void finish() {
    if (isBannerAllowed() && InterstitialBannerFactory.getInsterstitialSingleton().isReady()) {
        InterstitialBannerFactory.getInsterstitialSingleton().show();
    }
            finish();
}

It shows the AdMob banner and when user dismisses, it will finish the app the expected way.

BUT, when I include an InMobi interstital banner on mediation, it shows the banner but instantly finishes the app (strictly the remaining last activity of the app), without giving chance to user view the banner. It appears and suddenly finishes.

I know it happens because in some way that finish() on the end doesn't work fine with InMobi interstitial. I already tried to do something like this:

@Override
public void finish() {
    setAppFinishing(true);
    if (isBannerAllowed() && InterstitialBannerFactory.getInsterstitialSingleton().isReady()) {
        InterstitialBannerFactory.getInsterstitialSingleton().show();
    }
}

Note the setAppFinishing(true) at the begining and the removal of the finish() at the end.

It gets a little better, since it shows the InMobi interstitial. But prevents the user from exiting the app through back button.

Then I tried this on AdListerner's onDismissScreen() to complement above code:

@Override
public void onDismissScreen(Ad ad) {
    // prepares the next
    if (!isAppFinishing()) {
        InterstitialBannerFactory.loadAd();
    }
    else {
        finish();
    }
}

But it doesn't take effect, the behaviour is the same and app is not exiting.

Does anyone have a smarter solution?

BTW, i'm using latest versions of all libs involved.

Regards.

Это было полезно?

Решение

InMobi's interstitial is displayed on the same activity whereas AdMob's interstitial looks like its opening in a new activity.

To solve this, you could override the back button in your app.More details found at - Override back button to act like home button

Example -

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        Log.d(this.getClass().getName(), "back button pressed");
        if (interstitial.isReady()){
            interstitial.show();
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

Note: onCreate creates a new Interstitial Object and calls a load on it. Code to finally finish the app when interstitial is closed:

@Override
public void onDismissScreen(Ad ad) {
   finish();
}

-Akshay, SDK Developer, InMobi

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top