How to force Admob to refresh on Android

Viewed 21330

I have an app with Admob ads on it but I find that when I use it the ad almost never refreshes because I don't change activities, instead I just update a text view when buttons are pressed. I have tried searching this on Google but keep comming up short.

I would like to tell the app to refresh the add occasionally, such as after two button clicks or something like that. Does anyone know how to do this and potentially have some sample code for it?

7 Answers

declare adView in activity as data member , then create Timer Task as bellow in your constructor of the activity

adView = (AdView) findViewById(R.id.adView);
        TimerTask tt = new TimerTask() {

            @Override
            public void run() {
            MainActivity.this.runOnUiThread(new Runnable() {
                public void run() {
                    adView.loadAd(new AdRequest());
                }
            });

        }
    };

    Timer t = new Timer();
    t.scheduleAtFixedRate(tt, 0, 1000 * 60);
private AdRequest adRequest = null;
private void loadBannerRun() {
    if(adRequest != null) {
        adView.loadAd(adRequest);
        return;
    }
    adView.setAdUnitId(BANNER_AD_TEST);
    adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);
}

test please

Related