Advertisement
Guest User

asa

a guest
Jan 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. private InterstitialAd interstitial;
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. // TODO Auto-generated method stub
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_splash);
  8. iklanInterstitial();
  9.  
  10. }
  11.  
  12. @Override
  13. protected void onPause() {
  14. super.onPause();
  15. }
  16.  
  17.  
  18. public void iklanInterstitial(){
  19. interstitial = new InterstitialAd(this);
  20. interstitial.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
  21. AdRequest adRequest = new AdRequest.Builder().build();
  22. interstitial.loadAd(adRequest);
  23.  
  24.  
  25. interstitial.setAdListener(new AdListener() {
  26. @Override
  27. public void onAdClosed() {
  28. super.onAdClosed();
  29. Thread timerThread = new Thread() {
  30. public void run() {
  31. try {
  32. sleep(1000);
  33. } catch (InterruptedException e) {
  34. e.printStackTrace();
  35. } finally {
  36. startActivity(new Intent(SplashActivity.this, MainActivity.class));
  37. finish();
  38. }
  39. }
  40. };
  41. timerThread.start();
  42. }
  43.  
  44. @Override
  45. public void onAdLoaded() {
  46. super.onAdLoaded();
  47. if (interstitial.isLoaded()) {
  48. interstitial.show();
  49.  
  50. }
  51. }
  52.  
  53. @Override
  54. public void onAdFailedToLoad(int errorCode) {
  55. super.onAdFailedToLoad(errorCode);
  56. Thread timerThread = new Thread() {
  57. public void run() {
  58. try {
  59. sleep(1000);
  60. } catch (InterruptedException e) {
  61. e.printStackTrace();
  62. } finally {
  63. startActivity(new Intent(SplashActivity.this, MainActivity.class));
  64. finish();
  65. }
  66. }
  67. };
  68. timerThread.start();
  69. }
  70. });
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement