Android Interstitial ad -


i have problem interstitial ad in android. when application launches, ad shows , when user moves activity , returns main activity, ad shows again. should ad shows once in main activity , never shows again till next restart if user move activity? thank you! code:

  public void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     setcontentview(r.layout.tabpmnth_xm);      // create interstitial.     interstitial = new interstitialad(this);     interstitial.setadunitid("ca-app-pub-xxxxxxxxxxxx8x/x2xxxxxxxx");      adrequest aadrequest = new adrequest.builder()     .build();      // begin loading interstitial.     interstitial.loadad(aadrequest);      interstitial.setadlistener(new adlistener(){           public void onadloaded(){                displayinterstitial();           }    });      public void displayinterstitial() {      if (interstitial.isloaded()) {       interstitial.show();     }   } 

create application class app , this

public class myapplication extends application{      @override         public void oncreate(){         super.oncreate();         preferencemanager.getdefaultsharedpreferences(this).edit().putboolean("showinterstitial", true).apply();          }     } 

then in main activity

public void displayinterstitial() {      sharedpreferences sp = preferencemanager.getdefaultsharedpreferences(this);      if (interstitial.isloaded() && sp.getboolean("showinterstitial", true)){       interstitial.show();       preferencemanager.getdefaultsharedpreferences(this).edit().putboolean("showinterstitial", false).apply();      } } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -