-3

I implemented interstitial and banner ads on my app. they run well when auto rotation is off. but when auto rotation is turned On, and whenever screen orientation changes, my app starts to show interstitial ads repeatedly, it shows the ads till the device hangs. and don't have any effect of cancelling the ad or backpressing. I have also set the limit for ads as

Ad unit-level: 1 impr / 2 minutes
App-level: 1 impr / 2 minutes

but it doesn't work.

please suggest me a solution for this problem.

Or is it a bug of Admob?

I have written the code as:

@Override
protected void onCreate(Bundle savedInstanceState) {
    mInterstitialAd.setAdUnitId("*************");
    mInterstitialAd.loadAd(adRequest);

    mInterstitialAd.setAdListener(new AdListener(){
        public void onAdLoaded(){
            mInterstitialAd.show();
        }
    });

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_home);

}

@Override
protected void onStart() {
    super.onStart();
    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    }
}
  • if you can stop rotation then put the line after setContentview requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT – Harshit Trivedi Sep 02 '17 at 04:54
  • sir, it is not a solution for my question. i have already restricted the orientation to portrait. I want a good performance of my app with all the features, it also includes screen rotation. – Priyanshu Patel Sep 02 '17 at 08:28

1 Answers1

0
@Override
protected void onStart() {
    super.onStart();
    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    }
}

Loading ad in OnStart is incorrect way of implementing InterstitialAd. It is one of disallowed interstitial implementation "Disallowed example: Interstitial launches after page load". Your ads might be banned in such case. Read https://support.google.com/admob/answer/6201362?hl=en for all disallowed implementations.

OnStart is always called when the activity is becoming visible to the user. So your ads will be loaded multiple times which is again a violation of interstitial implementation ( There should be 2 clicks between 2 interstitial implementation). While you can overcome by creating local objects and showing it only once but still not correct way of implementation.

Interstitial should be loaded on specific user action. e.g. Refer to link https://developers.google.com/admob/android/interstitial for more examples.

mMyButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {
            Log.d("TAG", "The interstitial wasn't loaded yet.");
        }
    }
});
Amod Gokhale
  • 2,346
  • 4
  • 17
  • 32