i'm finishing a video application and i'm displaying interstitial ads when leaving the video activity. I just want to show it once every X minutes, but it seems to be showing every time i leave that screen.
This is my activity code.
OnCreate:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
videoId = b.getString("videoId");
setContentView(R.layout.youtube_player);
interstitialAd= new InterstitialAd(this);
interstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);
etc...
OnBackPressed:
@Override
public void onBackPressed() {
ShowAds();
}
private void ShowAds() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
super.onAdClosed();
finish();
}
});
}else{
super.onBackPressed();
}
}`
of course, it is setted like this into AdMob:
Note: my application is not published, so it is showing the "preview" o "sample". I am using my ad unit ID:
thanks,
Two options :
Interstitial ads show when I am leaving current Activity but only If I completed X minute on current Activity.
Don't wait for user to press back button and leave current Activity, just call
ShowAds()
fromonFinish()
method of Timer.I'll recommend to use 1st one because it not violate AdMob Ad policy and user experience too.
EDIT
You can also use X times counter, like when
X = 3
i.e After 3 times call ofonCreate()
method make eligible to show Ad.