启动屏幕应该持续3秒,但当应用程序在Genymotion仿真程序或安卓工作室仿真程序上运行时,它几乎完全跳过了它,这两个模拟器都与其他应用程序运行得很好。我不明白?
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 **
发布于 2017-07-04 08:45:36
你的屏幕代码应该是这样的
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);,因为处理程序中使用的延迟以毫秒为单位。
发布于 2017-07-04 08:47:14
你应该把你的秒(如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);
}
}发布于 2017-07-04 08:45:22
更改变量形式
int secondsDelayed = 4;至
int secondsDelayed = 4000;https://stackoverflow.com/questions/44901115
复制相似问题