启动屏幕显示太快,然后进入下一个Java类

启动屏幕显示太快,然后进入下一个Java类,java,android,android-xml,genymotion,Java,Android,Android Xml,Genymotion,启动屏幕应该持续3秒钟,但当应用程序在Genymotion Emulator或Android Studio Emulator上运行时,它几乎完全跳过了启动屏幕。这两个模拟器都能与其他应用程序完美地运行。我不明白 SplashScreen.java 包com.excepticetech.juliospizza原型; 导入android.content.Intent; 导入android.os.Bundle; 导入android.os.Handler; 导入android.support.v7.a

启动屏幕应该持续3秒钟,但当应用程序在Genymotion Emulator或Android Studio Emulator上运行时,它几乎完全跳过了启动屏幕。这两个模拟器都能与其他应用程序完美地运行。我不明白

SplashScreen.java

包com.excepticetech.juliospizza原型; 导入android.content.Intent; 导入android.os.Bundle; 导入android.os.Handler; 导入android.support.v7.app.AppActivity; 导入android.view.Window; /** *由Stormy Forrester于2016年3月20日创作。 */ 公共类SplashScreen扩展了AppCompative活动{ /**在首次创建活动时调用*/ @凌驾 public void onCreateBundle savedInstanceState{ super.onCreatesavedInstanceState; this.requestWindowFeatureWindow.FEATURE\u无\u标题; setContentViewR.layout.splash_屏幕; int secondsdlayed=4; new Handler.postDelayednew Runnable{ 公开募捐{ startActivitynew IntentSplashScreen.this, 显著性; 完成 } },第二层*3; }
} 更改变量形式

 int secondsDelayed = 4;


更改变量形式

 int secondsDelayed = 4;


您的splashscreen代码应该如下所示

 new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            Intent mainIntent = new Intent(SplashScreenClass.this, Homescreen.class);
            startActivity(mainIntent);
            finish();
            // close this activity
        }
    }, 3000);

因为处理程序中使用的延迟以毫秒为单位。

您的splashscreen代码应该是这样的

 new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            Intent mainIntent = new Intent(SplashScreenClass.this, Homescreen.class);
            startActivity(mainIntent);
            finish();
            // close this activity
        }
    }, 3000);

因为处理程序中使用的延迟以毫秒为单位。

您应该将秒数(如4)乘以1000

因为你必须在毫秒内给出它

尝试将代码更改为

 @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.splash_screen);

    int secondsDelayed = 4;
    new Handler().postDelayed(new Runnable() {
      public void run() {
        startActivity(new Intent(SplashScreen.this,
          SignInActivity.class));
        finish();
      }
    }, secondsDelayed * 1000);
  }
}

你应该把你的秒数(如4)乘以1000

因为你必须在毫秒内给出它

尝试将代码更改为

 @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.splash_screen);

    int secondsDelayed = 4;
    new Handler().postDelayed(new Runnable() {
      public void run() {
        startActivity(new Intent(SplashScreen.this,
          SignInActivity.class));
        finish();
      }
    }, secondsDelayed * 1000);
  }
}

根据本教程,我尝试将启动屏幕作为窗口背景:


然后在主屏幕的OnCreate中设置ContentView之前调用Thread.sleep2000ms。

我尝试按照本教程将启动屏幕作为窗口背景:


然后在主屏幕的OnCreate中设置ContentView之前调用Thread.sleep2000ms。

延迟为毫秒。4秒为4000毫秒,秒数显示=4000;并删除*3延迟为毫秒。4秒为4000毫秒,秒数显示=4000;为了清晰起见,我会使用TimeUnit.SECONDS.tomills3为了清晰起见,我会使用TimeUnit.SECONDS.tomills3