How to finish the Ads_Fullscreen Activity in 8 seconds and lunch the MainActivity after wards?

帅比萌擦擦* 提交于 2019-12-25 00:31:11

问题


Two situation for Splash Screen

  1. if ads is enable then Splash Screen time will be 2 seconds and Ads_Fullscreen time will be 8 seconds then final Main Activity will come.

  2. if ads is not enable then Splash Screen time will be 5 seconds and then Main Activity will come.

This is code for splash screen

 new Handler().postDelayed(new Runnable() {
      @Override
      public void run() {
          Intent i;
          if (prefManager.isFirstTimeLaunch()){
              i = new Intent(SplashScreen.this,WelcomeActivity.class);
              prefManager.setFirstTimeLaunch(false);
          }else if(bn_bstatus.equals("enable")) {
              i = new Intent(SplashScreen.this,Ads_Fullscreen.class);

          }else{
              i = new Intent(SplashScreen.this,MainActivity.class);
          }
          startActivity(i);
          finish();
      }
  },SPLASH_TIME_OUT);

回答1:


set default SPLASH_TIME_OUT as 5000 milliseconds.

public final int SPLASH_TIME_OUT = 5000;

For SplashScreen Activity

final Intent intent;
if (ads.enable()) {
    intent = new Intent(SplashScreen.this, WelcomeActivity.class);
    prefManager.setFirstTimeLaunch(false);
} else if (bn_bstatus.equals("enable")) {
    intent = new Intent(SplashScreen.this, Ads_Fullscreen.class);
    SPLASH_TIME_OUT = 2000;
} else {
    intent = new Intent(SplashScreen.this, MainActivity.class);
}
new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        startActivity(intent);
        finish();
    }
}, SPLASH_TIME_OUT);

For Ads_Fullscreen Activity

SPLASH_TIME_OUT = 8000;
new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            // start MainActivity
        }
    }, SPLASH_TIME_OUT);


来源:https://stackoverflow.com/questions/55258163/how-to-finish-the-ads-fullscreen-activity-in-8-seconds-and-lunch-the-mainactivit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!