Created
May 1, 2018 09:28
-
-
Save Ultima2876/c4909cebd5dfd755205ef558dc89c9d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean isShowing; | |
private final int maxChecks = 3; | |
private int currentChecks = 0; | |
protected void onCreate(Bundle savedInstanceState) { | |
//... | |
startChecking(); | |
} | |
private void startChecking(){ | |
currentChecks = 0; | |
checkAndShowAd(); | |
} | |
private void checkAndShowAd(){ | |
if( isShowing ) return; | |
Log.d("QWERTY", "checkAndShowAd() #"+currentChecks); | |
boolean isAdReady = Enhance.isInterstitialReady(); | |
// isAdReady = false; | |
if( isAdReady ){ | |
Log.d("QWERTY", "Ad is ready, show it!"); | |
showAd(); | |
}else{ | |
if( currentChecks + 1 > maxChecks ){ | |
Log.d("QWERTY", "max checks reached!"); | |
return; | |
} | |
currentChecks++; | |
Log.d("QWERTY", "Ad is not ready, schedule next check."); | |
Handler handler = new Handler(); | |
handler.postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
checkAndShowAd(); | |
} | |
}, 1000); | |
} | |
} | |
private void showAd(){ | |
isShowing = true; | |
Enhance.showInterstitialAd(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment