Danny Boy
Danny Boy

Reputation: 1

Load Interstitial Ad on App start in Android Studio

I'm a newbie in Android Studio, I made this much progress (There's also coding for webview that I skipped) after reading on Google Developer help section but now I want to load as the app starts as this is the javascript of my home page.

import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MobileAds.initialize(this, "APP+ID");

        InterstitialAd mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("AD_ID");
        mInterstitialAd.loadAd(new AdRequest.Builder().build());

    } 
}

Upvotes: 0

Views: 1253

Answers (1)

Vinil Prabhu
Vinil Prabhu

Reputation: 1289

Add this in your onCreate

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

in your code you are just loading the add but not showing it.

Upvotes: 1

Related Questions