Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private InterstitialAd interstitial;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_splash);
- iklanInterstitial();
- }
- @Override
- protected void onPause() {
- super.onPause();
- }
- public void iklanInterstitial(){
- interstitial = new InterstitialAd(this);
- interstitial.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
- AdRequest adRequest = new AdRequest.Builder().build();
- interstitial.loadAd(adRequest);
- interstitial.setAdListener(new AdListener() {
- @Override
- public void onAdClosed() {
- super.onAdClosed();
- Thread timerThread = new Thread() {
- public void run() {
- try {
- sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- startActivity(new Intent(SplashActivity.this, MainActivity.class));
- finish();
- }
- }
- };
- timerThread.start();
- }
- @Override
- public void onAdLoaded() {
- super.onAdLoaded();
- if (interstitial.isLoaded()) {
- interstitial.show();
- }
- }
- @Override
- public void onAdFailedToLoad(int errorCode) {
- super.onAdFailedToLoad(errorCode);
- Thread timerThread = new Thread() {
- public void run() {
- try {
- sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- startActivity(new Intent(SplashActivity.this, MainActivity.class));
- finish();
- }
- }
- };
- timerThread.start();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement