问题
I have success integrate the interstitial ad from admob in my application from this tutorial, i want to ask, how to change interstitial ads every X minute
回答1:
It is usually not a good idea to show interstitials every minute, because you'll end up interrupting the user flow (interstitial may appear while user is actively using your app). Better use natural breaks to show ads.
Check also the best practices for admob interstitial implementation:
Repeated number of interstitials (not recommended)
Don’t overwhelm users with interstitial ads. Repeated interstitial ads often lead to poor user experiences and accidental clicks. If you’re implementing interstitials based on a user action (e.g., selecting an option), avoid implementing an interstitial ad for every user action.
If you are implementing interstitial ads based on a time interval (e.g., every 60 seconds), avoid using brief durations in between interstitial ads.
回答2:
It is against google policy but if you still want to implement this
private void setUpInterstitialAd() {
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
interstitialAd.loadAd(new AdRequest.Builder().build());
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
// Load the next interstitial.
interstitialAd.loadAd(new AdRequest.Builder().build());
}
});
}
private void scheduleInterstitial() {
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
displayInterstitial();
setUpInterstitialAd();
}
});
}
}, 1, 5, TimeUnit.MINUTES);
}
private void displayInterstitial() {
if (interstitialAd != null) {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setUpInterstitialAd();
scheduleInterstitial();
}
来源:https://stackoverflow.com/questions/26727454/integrating-interstitial-ads-and-show-every-x-minute