Why does my Admob interstitial ad show at the wrong time?

  • Thread starter Darkmisc
  • Start date
  • Tags
    Time
In summary, the conversation is about an issue with showing an interstitial ad while navigating from MainActivity to Activity2. The ad only shows when using the system back button from Activity2 to MainActivity. The individual has tried replacing MainActivity.this with Activity2 in the code but it does not work. The code for loading and calling the ads is also provided. The issue is eventually resolved.
  • #1
Darkmisc
220
31
TL;DR Summary
I'd like to show an interstitial ad when a button is clicked to go from MainActivity to Activity2. Instead, the ad shows while clicking back from Activity2 to MainActivity.
Hi everyone

I'd like to show an interstitial ad while going from MainActivity to Activity2. Instead, the ad only shows when clicking back from Activity2 to the MainActivity (using the system back button. Activity2 doesn't have its own back button).

Does anyone know what I've done wrong?

I have a button in MainActivity that loads Activity2. I have the following in the code for the button.
show ad:
if (mInterstitialAd != null) {
            mInterstitialAd.show(MainActivity.this);
        } else {
            Log.i(TAG, "Ad failed to load");

    }

I thought I could solve the problem by replacing MainActivity.this with Activity2, but it get a red underline. I've tried "Activity2," "Activity2.class" and "Activity2.java."

The below code is for loading and calling the ads.

loading and calling ads:
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {
            }
        });
        loadInterstitial();
    public void loadInterstitial(){
        AdRequest adRequest = new AdRequest.Builder().build();
        InterstitialAd.load(this, getString(R.string.interstitial_ad_unit_id), adRequest, new             InterstitialAdLoadCallback() {

            @Override
            public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
                super.onAdLoaded(interstitialAd);
                Log.d(TAG, "Ad loaded successfully");
                mInterstitialAd = interstitialAd;
                mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
                    @Override
                    public void onAdFailedToShowFullScreenContent(@NonNull AdError adError) {
                        super.onAdFailedToShowFullScreenContent(adError);
                        Log.d(TAG, "Ad failed to show");

                    }

                    @Override
                    public void onAdShowedFullScreenContent() {
                        super.onAdShowedFullScreenContent();
                        Log.d(TAG, "Ad shown successfully");
                        mInterstitialAd = null;

                    }                    @Override
                    public void onAdDismissedFullScreenContent() {
                        super.onAdDismissedFullScreenContent();
                        Log.d(TAG, "Ad dismissed");
                    }
                });
            }

            @Override
            public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                super.onAdFailedToLoad(loadAdError);
                Log.i(TAG, "onAdLoaded");
                mInterstitialAd = null;
            }
        });

        }
Thanks
 
Technology news on Phys.org
  • #2
nvm. It works now.
 

FAQ: Why does my Admob interstitial ad show at the wrong time?

Why does my Admob interstitial ad show at the wrong time?

There could be several reasons why your Admob interstitial ad is showing at the wrong time. One common reason is that the ad loading process is not properly synchronized with your app's content, leading to the ad being displayed at an inconvenient time for the user.

Is there a way to control when Admob interstitial ads are displayed?

Yes, you can control when Admob interstitial ads are displayed by implementing proper ad loading logic in your app. Make sure to load the ad at an appropriate time, such as during natural breaks in your app's content, to ensure a better user experience.

Could the issue be related to the ad request settings in my Admob account?

It is possible that the issue with your Admob interstitial ad showing at the wrong time is related to the ad request settings in your Admob account. Double-check your ad request settings to ensure they are configured correctly and aligned with your app's content.

Are there any best practices for displaying Admob interstitial ads?

Yes, there are best practices for displaying Admob interstitial ads to maximize revenue and user engagement. Make sure to test different ad placement strategies, such as showing ads during natural breaks or after specific user actions, to find the optimal timing for displaying ads in your app.

What steps can I take to troubleshoot the issue of Admob interstitial ads showing at the wrong time?

To troubleshoot the issue of Admob interstitial ads showing at the wrong time, you can start by reviewing your ad loading logic and ensuring it is properly synchronized with your app's content. Additionally, check your ad request settings and consider implementing ad mediation to improve ad targeting and relevance for your users.

Similar threads

Back
Top