-2

Interstitial ads still show after my application is closed or even if user left the app which violate the Admob police. How to stop that, noting that I followed the implementation guide while adding the code to my application ?

I use a navigation drawer as a main activity which where I implemented my interstitial ad.

    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxxxxxxxxxxxxx");
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            mInterstitialAd.show(); }

    });
Fadl
  • 21
  • 3
  • 1
    Pro tip: it is best to use real words here. Words like "kinda" and "plz" tend to attract downvotes, as they may irritate some readers. Stick to technical writing as much as you can, please. – halfer Oct 30 '18 at 22:35
  • 1
    sorry for that and i will avoid adding any abbreviations – Fadl Nov 07 '18 at 02:38

1 Answers1

0

Create an onPause() method. (( The system calls this method as the first indication that the user is leaving your activity (though it does not always mean the activity is being destroyed) )).

@Override
protected void onPause() {
    handler.removeCallbacks(your handler name here);
    interAd =null
    super.onPause();
}

Others: onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy()

More info here --> https://developer.android.com/guide/components/activities/activity-lifecycle

RAPTORp
  • 90
  • 6
  • 1
    i kinda now going with that code protected void onPause() { if(mInterstitialAd != null){ mInterstitialAd.setAdListener(null); } super.onPause(); } protected void onResume() { if (mInterstitialAd.isLoaded()) { mInterstitialAd.show(); } super.onResume(); } i will see if it work or not .. thanks alot for answering my question – Fadl Oct 27 '18 at 04:00