Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ultima2876/c4909cebd5dfd755205ef558dc89c9d2 to your computer and use it in GitHub Desktop.
Save Ultima2876/c4909cebd5dfd755205ef558dc89c9d2 to your computer and use it in GitHub Desktop.
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