Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Variable Declaration
- private InterstitialAd interstitialAd;
- //Prepare for load Interstitial Ad on Fragment
- //call the function loadInterstitialAd() in the onCreate method
- private void loadInterstitialAd() {
- interstitialAd = new InterstitialAd(getActivity());
- interstitialAd.setAdUnitId(getResources().getString(R.string.admob_interstitial_id));
- interstitialAd.loadAd(new AdRequest.Builder().build());
- interstitialAd.setAdListener(new AdListener() {
- @Override
- public void onAdClosed() {
- //your method here when the ad is closed
- interstitialAd.loadAd(new AdRequest.Builder().build());
- }
- });
- }
- //Prepare for load Interstitial Ad on Activity
- //call the function loadInterstitialAd() in the onCreate method
- private void loadInterstitialAd() {
- interstitialAd = new InterstitialAd(getApplicationContext());
- interstitialAd.setAdUnitId(getResources().getString(R.string.admob_interstitial_id));
- interstitialAd.loadAd(new AdRequest.Builder().build());
- interstitialAd.setAdListener(new AdListener() {
- @Override
- public void onAdClosed() {
- //your method here when the ad is closed
- interstitialAd.loadAd(new AdRequest.Builder().build());
- }
- });
- }
- //Display Interstitial Ad
- //call the function showInterstitialAd() in the onItemClickListener or other method
- private void showInterstitialAd() {
- if (interstitialAd.isLoaded()) {
- interstitialAd.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement