Created
March 12, 2018 02:55
-
-
Save malikkurosaki/b0e96d2ab57b9e2fdfac90e3ebe6bb44 to your computer and use it in GitHub Desktop.
create schedule adroid studio, make ads show every second as well
This file contains hidden or 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
| public class MainActivity extends AppCompatActivity { | |
| private InterstitialAd interstitialAd; | |
| private ScheduledExecutorService scheduledExecutorService; | |
| private Boolean isVisible; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| AdView adView = findViewById(R.id.adView); | |
| AdRequest adRequest = new AdRequest.Builder().build(); | |
| adView.loadAd(adRequest); | |
| pripareADs(); | |
| } | |
| @Override | |
| protected void onStart() { | |
| super.onStart(); | |
| isVisible = true; | |
| if (scheduledExecutorService == null){ | |
| scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); | |
| scheduledExecutorService.scheduleAtFixedRate(new Runnable() { | |
| @Override | |
| public void run() { | |
| runOnUiThread(new Runnable() { | |
| @Override | |
| public void run() { | |
| if (interstitialAd.isLoaded()){ | |
| interstitialAd.show(); | |
| }else{ | |
| Toast.makeText(getApplicationContext(),"iklan gk uncul",Toast.LENGTH_LONG).show(); | |
| } | |
| pripareADs(); | |
| } | |
| }); | |
| } | |
| },10,10, TimeUnit.SECONDS); | |
| } | |
| } | |
| private void pripareADs() { | |
| interstitialAd = new InterstitialAd(this); | |
| interstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); | |
| interstitialAd.loadAd(new AdRequest.Builder().build()); | |
| } | |
| @Override | |
| protected void onStop() { | |
| super.onStop(); | |
| scheduledExecutorService.shutdownNow(); | |
| scheduledExecutorService = null; | |
| isVisible = false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment