Droid Genie
Droid Genie

Reputation: 361

How to load Admob ads after certain time of app load?

Hi I am creating an Android app. I want to show Interstitial ads after some time of app load. Say 60 seconds.

The Code that I had developed shows add instantly as soon as the App is launced, I need that it should be shown after a delay of say 60 sec. But in the mean time the App should perform the operation and should not wait or sleep.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    interAd = new InterstitialAd(this);
    interAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
        .build();
    interAd.loadAd(adRequest);
    interAd.setAdListener(new AdListener() {
        @Override

        public void onAdLoaded() {
            displayinterstitial();
        }
    });
}

public void displayinterstitial() {
    if (interAd.isLoaded()) {
        interAd.show();
    }
}

Help me to resolve my issue.

Upvotes: 1

Views: 4883

Answers (2)

Bhargav Thanki
Bhargav Thanki

Reputation: 4954

Try this

new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                //Your code to show add

            }
        }, 60000);

Your new code would be

@Override
public void onCreate( Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {

            interAd = new InterstitialAd(this);
            interAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
            AdRequest adRequest = new AdRequest.Builder()
                    .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
                    .build();
            interAd.loadAd(adRequest);
            interAd.setAdListener(new AdListener() {
                @Override

                public void onAdLoaded() {
                    displayinterstitial();
                }
            });

        }
    } , 60000);
}

Upvotes: 2

Pravinsingh Waghela
Pravinsingh Waghela

Reputation: 2534

Try this it could help you.

interAd = new InterstitialAd(this);
            interAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
            AdRequest adRequest = new AdRequest.Builder()
                    .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
                    .build();
    new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {

            interAd.loadAd(adRequest);

                }
            }, 1000); // After one Sec

Upvotes: 0

Related Questions