I have 3 activity A, B, and C and I am showing interstitial ad in activity B. But problem is if I instantly back in activity A, interstitial appear in activity A. If I instantly go next activity C, interstitial appear in activity C. But I want interstitial will show only in activity B. Google haven't accept my app update for this reason.
            Asked
            
        
        
            Active
            
        
            Viewed 115 times
        
    2 Answers
1
            
            
        try this way
InterstitialAd mInterstitial = new InterstitialAd(this);
                mInterstitial.setAdUnitId(getResources().getString(Your_init_id));
                AdRequest adRequest = new AdRequest.Builder().build();
                mInterstitial.setAdListener(new AdListener() {
                    @Override
                    public void onAdLoaded() {
                        Log.d("==","onAdLoaded");
                        mInterstitial.show();
                    }
                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        // Code to be executed when an ad request fails.
                        Log.d("==","onAdFailedToLoad"+errorCode);
                        moveToOtherActivity();
                    }
                    @Override
                    public void onAdOpened() {
                        // Code to be executed when the ad is displayed.
                    }
                    @Override
                    public void onAdLeftApplication() {
                        // Code to be executed when the user has left the app.
                    }
                    @Override
                    public void onAdClosed() {
                        // Code to be executed when when the interstitial ad is closed.
                        Log.d("==","onAdClosed");
                        moveToOtherActivity();
                    }
                });
                mInterstitial.loadAd(adRequest);
            }
         private void moveToOtherActivity() {
            Intent intent;
            intent = new Intent(this,Activity_which_you_want_to_display_after_interstitial .class);
            startActivity(intent);
            finish();
        }
        pratik vekariya
        
- 1,105
 - 1
 - 8
 - 14