Guest User

Untitled

a guest
Mar 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2. private InterstitialAd interstitialAd;
  3. private ScheduledExecutorService scheduledExecutorService;
  4. private Boolean isVisible;
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9.  
  10. AdView adView = findViewById(R.id.adView);
  11. AdRequest adRequest = new AdRequest.Builder().build();
  12. adView.loadAd(adRequest);
  13.  
  14. pripareADs();
  15.  
  16.  
  17. }
  18.  
  19. @Override
  20. protected void onStart() {
  21. super.onStart();
  22. isVisible = true;
  23. if (scheduledExecutorService == null){
  24. scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
  25. scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
  26. @Override
  27. public void run() {
  28. runOnUiThread(new Runnable() {
  29. @Override
  30. public void run() {
  31. if (interstitialAd.isLoaded()){
  32. interstitialAd.show();
  33. }else{
  34. Toast.makeText(getApplicationContext(),"iklan gk uncul",Toast.LENGTH_LONG).show();
  35. }
  36. pripareADs();
  37.  
  38. }
  39. });
  40. }
  41. },10,10, TimeUnit.SECONDS);
  42. }
  43. }
  44.  
  45. private void pripareADs() {
  46. interstitialAd = new InterstitialAd(this);
  47. interstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
  48. interstitialAd.loadAd(new AdRequest.Builder().build());
  49. }
  50.  
  51. @Override
  52. protected void onStop() {
  53. super.onStop();
  54. scheduledExecutorService.shutdownNow();
  55. scheduledExecutorService = null;
  56. isVisible = false;
  57. }
  58. }
Add Comment
Please, Sign In to add comment