启动画面显示速度太快,然后进入下一个 Java Class
Splash Screen is displaying too fast and then going into the next Java Class
启动画面应该持续 3 秒,但当应用程序在 Genymotion 模拟器 或 [= 上 运行 时,它几乎完全跳过它33=] Studios Emulator 这两个模拟器 运行 与其他应用程序完美结合。我不明白?
SplashScreen.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**
更改您的变量形式
int secondsDelayed = 4;
到
int secondsDelayed = 4000;
您的初始屏幕代码应该像这样
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);
}
}
我尝试按照本教程将启动画面作为 window 背景:https://medium.com/android-news/right-way-to-create-splash-screen-on-android-e7f1709ba154
然后在主屏幕的 OnCreate 中的 setContentView 之前调用 Thread.sleep(2000ms)。
启动画面应该持续 3 秒,但当应用程序在 Genymotion 模拟器 或 [= 上 运行 时,它几乎完全跳过它33=] Studios Emulator 这两个模拟器 运行 与其他应用程序完美结合。我不明白?
SplashScreen.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**
更改您的变量形式
int secondsDelayed = 4;
到
int secondsDelayed = 4000;
您的初始屏幕代码应该像这样
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);
}
}
我尝试按照本教程将启动画面作为 window 背景:https://medium.com/android-news/right-way-to-create-splash-screen-on-android-e7f1709ba154
然后在主屏幕的 OnCreate 中的 setContentView 之前调用 Thread.sleep(2000ms)。