Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show admob interstitial on app exit

how to show ad mob interstitial ad on app exit. I tried it using onBackPressed() method but getting errors Code for interstitial ad

interstitial = new InterstitialAd(this, "AD_ID");


    AdRequest adRequest = new AdRequest();


    interstitial.loadAd(adRequest);


    interstitial.setAdListener(this);
  }
    @Override
      public void onReceiveAd(Ad ad) {

        if (ad == interstitial) {
          interstitial.show();
        }

    }

What is the correct way to do it.

like image 424
samdonly1 Avatar asked Sep 28 '13 17:09

samdonly1


People also ask

How do I show AdMob ads in app?

After you've set up an app in AdMob and added an ad unit to it, the last step is to implement the ad unit in your app's code. Follow the instructions in the Google Developers Get Started guide for Android or iOS. You'll need your app ID and ad unit ID during implementation.

How do you show interstitial ad before launching new activity after click a button?

I use option menu button to go to second activity. When user click on that menu button interstitial Ad show after launching second activity.

How do I close an interstitial ad programmatically?

ACTION_DOWN, KeyEvent. KEYCODE_BACK)); As whenever you press on back button the interstitial ad is closed so firing the back button event will eventually close the interstitial ad.


2 Answers

I just had a nice talk with an employee at Admob about how to increase my ad revenue. And his recommendation was to add an interstitial when the players exit my game apps. I did not read through all the terms and conditions but I do believe that the Admob official knows the standard regulations and would not recommend this behavior if it was not allowed.

Technically I am going to implement it in this way:

1) Catch when the user clicks on my exit button or hits the back button on the main screen

2) Check if an interstitial is loaded and ready to be displayed

-> 3a) if it is not ready, i let the user quit without delay

-> 3b) if it is ready, I show the interstitial and listen to it being closed, when it is closed, I exit the app automatically

like image 153
Björn Kechel Avatar answered Sep 21 '22 03:09

Björn Kechel


Don't attempt to show an Ad on app exit, as RSenApps says show it at a key point in your app instead.

If your problem is that when the interstitial shows it causes the views to be redrawn on your Activity, then you need to persist or cache the drawing state of your Activity so that previous state can be quickly redrawn as needed.

like image 38
William Avatar answered Sep 23 '22 03:09

William