I am calling showAd()
inside OnResume
to call for interstitialAd.
ShowAd()
public void showAd()
{
SavedFrequency = getSharedPreferences("adfreq", MODE_PRIVATE);
AdfrequencyInt = SavedFrequency.getInt("adfreq", 0);
AdfrequencyInt++;
if (AdfrequencyInt > 59)
{
AdfrequencyInt = 0;
}
Toast.makeText(this, ""+AdfrequencyInt, Toast.LENGTH_SHORT).show();
SharedPreferences.Editor preferencesEditorF1 = SavedFrequency.edit();
preferencesEditorF1.putInt("adfreq", AdfrequencyInt);
preferencesEditorF1.apply();
if (AdfrequencyInt % 10 == 0)
{
interstitialAd = new InterstitialAd(this, MY_PUBLISHER_ID); // Create an ad
interstitialAd.setAdListener(this); // Set the AdListener.
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
interstitialAd.loadAd(adRequest);
}
}
Question:
The ad can be shown out, but is usually delayed, i.e. when I have already started off another activity, it is still loading in the backgorund and then suddenly the ad pops out. I would like to ask how could the ad be loaded first and stored in the background such that the ad will only be shown when I return to this activity?
Thanks!