AdMob Interstitial with Viewpager - Issues after d

2019-02-18 00:35发布

问题:

I have implemented AdMob interstitial when the viewpager fragments are swiped/ changed. Depending on a couple of conditions (primarily time driven), the requested interstitials are loaded during the swipe by calling the following code in the onPageSelected in viewpager listener:

                        SharedPreferences myPreferences = getSharedPreferences("AdvertTime", MainActivity.this.MODE_PRIVATE);
                    long retrievedTime = myPreferences.getLong("ADTIME", System.currentTimeMillis());
                    boolean myBool = retrievedTime < System.currentTimeMillis();
                    boolean myBool1 = onLaunchTime < System.currentTimeMillis();
                    if (mInterstitialAd.isLoaded() && myBool && myBool1) {
                        mInterstitialAd.show();

                        SharedPreferences.Editor prefEditor = myPreferences.edit();
                        long myLong = System.currentTimeMillis() + MainActivity.myAdDelay;
                        prefEditor.putLong("ADTIME", myLong);
                        prefEditor.commit();

                    }

After the ad is dismissed with the 'X', the apps starts to behave strangely, primarily the actionbar icons are not changed on fragment swipes and the navigation drawer acts strangely in highlighting the wrong options than what is clicked. Incidentally, this problem disappears when a new activity is run and closed, or the app is paused and resumed.