Java Splashscreen只是偶尔显示
我通过以下方式定义了splashscreen:Java Splashscreen只是偶尔显示,java,android,Java,Android,我通过以下方式定义了splashscreen: /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ExceptionHandler.register(this); setFullscreen()
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ExceptionHandler.register(this);
setFullscreen();
splashScreen();
}
private void splashScreen() {
runOnUiThread(new Runnable() {
@Override
public void run() {
setContentView(R.layout.splashscreen);
splash = (ImageView) findViewById(R.id.splashscreenLayer);
startSplashTime = new Date();
}
});
new LoadingThread().start();
}
private class LoadingThread extends Thread {
@Override
public void run() {
checkNetwork();
}
}
在checkNetwork()方法的特定条件下,调用stopSplash方法:
public void stopSplash() {
Message msg = new Message();
msg.what = STOPSPLASH;
Date endSplashTime = new Date();
long time = endSplashTime.getTime() - startSplashTime.getTime();
System.out.println("Time Splashscreen was displayed: " + time);
if (time < SPLASH_MIN_TIME) {
long delay = SPLASH_MIN_TIME - time;
System.out.println("Delay Splashscreen for: " + delay);
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
splashHandler.sendMessage(msg);
} else {
System.out.print("Show Splashscreen now");
splashHandler.sendMessage(msg);
}
}
private Handler splashHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case STOPSPLASH:
splash.setVisibility(View.GONE);
break;
}
super.handleMessage(msg);
}
};
public void stopplash(){
Message msg=新消息();
msg.what=停止飞溅;
日期endSplashTime=新日期();
long time=endSplashTime.getTime()-startSplashTime.getTime();
System.out.println(“显示飞溅屏幕的时间:“+时间”);
如果(时间<飞溅时间){
长延时=飞溅时间-最小时间-时间;
System.out.println(“延迟屏幕:”+延迟);
试一试{
睡眠(延迟);
}捕捉(中断异常e){
e、 printStackTrace();
}
splashHandler.sendMessage(msg);
}否则{
系统输出打印(“立即显示屏幕”);
splashHandler.sendMessage(msg);
}
}
私有处理程序splashHandler=新处理程序(){
@凌驾
公共无效handleMessage(消息消息消息){
开关(msg.what){
案例停止飞溅:
splash.setVisibility(View.GONE);
打破
}
超级handleMessage(msg);
}
};
问题是,有时候(可能是10个中的1个),如果我直接从Eclipse启动应用程序,Splashscreen不会显示,而只是一个黑屏
其他问题:如果我重新启动应用程序,例如在单击设备上的“后退”按钮调用onDestroy()后,Splashscreen几乎从未显示
有什么提示吗
我的假设是:加载线程的启动速度可能比可运行线程的启动速度“更快”,因此网络工作人员在设置Splashscreen之前就完成了吗?您可以尝试在实现中使用倒计时。在您的第一个活动中,启动一个倒计时程序,每隔一段时间检查onTick()中是否有同步的boolean finishedLoading,并在onFinish()中有某种超时(15秒左右),而加载是在另一个线程中完成的,该线程在加载完成时将finishedLoading设置为true。您可以尝试在实现中使用倒计时。在您的第一个活动中,启动一个倒计时程序,每隔一段时间检查onTick()中是否有同步的boolean finishedLoading,并在onFinish()中有某种超时(15秒左右),而加载是在另一个线程中完成的,该线程在加载完成时将finishedLoading设置为true。可能在v=下一个活动开始之前启动屏幕没有终止。。只是想一想。在v=下一个活动开始之前,启动屏幕可能不会终止。。只是一个想法