Advertisement
solodroid

Implementation of Interstitial Ad after Splash Screen

Nov 22nd, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. public class ActivitySplash extends AppCompatActivity {
  2.  
  3.     private InterstitialAd interstitialAd;
  4.  
  5.     @Override
  6.     public void onCreate(Bundle savedInstanceState) {
  7.         super.onCreate(savedInstanceState);
  8.  
  9.         setContentView(R.layout.activity_splash);
  10.  
  11.         loadInterstitialAd();
  12.  
  13.         new CountDownTimer(5000, 1000) {
  14.             @Override
  15.             public void onFinish() {
  16.                 Intent intent = new Intent(getBaseContext(), MainActivity.class);
  17.                 startActivity(intent);
  18.                 finish();
  19.  
  20.                 showInterstitialAd();
  21.             }
  22.  
  23.             @Override
  24.             public void onTick(long millisUntilFinished) {
  25.  
  26.             }
  27.         }.start();
  28.  
  29.     }
  30.  
  31.     private void loadInterstitialAd() {
  32.         interstitialAd = new InterstitialAd(getApplicationContext());
  33.         interstitialAd.setAdUnitId(getResources().getString(R.string.admob_interstitial_id));
  34.         interstitialAd.loadAd(new AdRequest.Builder().build());
  35.         interstitialAd.setAdListener(new AdListener() {
  36.             @Override
  37.             public void onAdClosed() {
  38.  
  39.             }
  40.         });
  41.     }
  42.  
  43.     private void showInterstitialAd() {
  44.         if (interstitialAd.isLoaded()) {
  45.             interstitialAd.show();
  46.         }
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement