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



初始屏幕应该持续 3 秒,但当应用程序在Genymotion模拟器或Android Studios 模拟器上运行时,它几乎完全跳过它,这两个模拟器都可以与其他应用程序完美运行。我不明白?

启动画面.java

package com.transcendencetech.juliospizzaprototype;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
/**
* Created by Stormy Forrester on 20/03/2016.
*/
public class SplashScreen extends AppCompatActivity {
/** Called when the activity is first created. */
@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 * 3);
}
}

**splash_screen,XML **

您应该将秒(例如 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);
}
}

更改变量形式

int secondsDelayed = 4;

int secondsDelayed = 4000;

我尝试按照本教程将初始屏幕作为窗口背景:https://medium.com/android-news/right-way-to-create-splash-screen-on-android-e7f1709ba154

然后在主屏幕的OnCreate中设置ContentView之前调用Thread.sleep(2000ms(。

最新更新