简体   繁体   中英

Ads stopped working after a year when app is build from newer version of Android Studio

About a year ago i finished a super simple game in android studio and published it. Now i wanted to make a small update and show ads on more proper place. But ads won't work at all - code is the same as it was, but ads just won't load.

My account is not disabled since if I download my game from playstore ads still work.

I use different version of android studio, so the project upgraded itself, but I don't know if it changed graddle or manifest or something so this could happen.

mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxxxxxxx/xxxxxxxx");
    mInterstitialAd.loadAd(new AdRequest.Builder().build());


mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded () {
            if(enableAd) {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
            }
        }
    });

Use onAdClosed() in your AdListener to reload your ad each time is has been displayed, and create your initial Ad as part of the mainActivity.create() .

Use mInterstitialAd.show() anywhere in your app when you want to show the ad. After it is shown, it closes and will reload the next ad.

What this does is buffers your Ad. Whenever you show the interstitial ad, it shows the one that is already loaded, then reloads a new one after you've shown the ad. Makes for a quicker ad.show().

mInterstatialAd = new InterstitialAd(getBaseContext());
  mInterstatialAd.setAdUnitId(getResources()
                  .getString(R.string.AdmobTestInterstitial));
mInterstitialAd.setAdListener(new AdListener() {
    @Override
    public void onAdClosed () {
        mInterstatialAd.loadAd(myAdRequest);
    }
});
public void showMyInterstitialAd(){
    if(mInterstitialAd!=null &&
       mInstitialAd.isLoaded()) mInterstitialAd.show();
}

good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM