当您通过屏幕按钮进入主屏幕然后再次点击应用程序打开它时,启动画面将无法完成,它只是返回到启动画面?为什么呢?
我正在调用finish();那么为什么它不会混淆
package com.webcraftbd.radio;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
public class SplashScreen extends Activity
{
// Set the display time, in milliseconds (or extract it out as a configurable parameter)
private final int SPLASH_DISPLAY_LENGTH = 3000;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}
@Override
protected void onResume()
{
super.onResume();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
// Obtain the sharedPreference, default to true if not available
boolean isSplashEnabled = sp.getBoolean("isSplashEnabled", true);
if (isSplashEnabled)
{
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
//Finish the splash activity so it can't be returned to.
SplashScreen.this.finish();
// Create an Intent that will start the main activity.
Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class);
SplashScreen.this.startActivity(mainIntent);
}
}, SPLASH_DISPLAY_LENGTH);
}
else
{
// if the splash is not enabled, then finish the activity immediately and go to main.
finish();
Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class);
SplashScreen.this.startActivity(mainIntent);
}
}}
答案 0 :(得分:0)
如果它只是一个闪屏,为什么你不使用简单的东西?等;
protected void onCreate(Bundle radioPlayer) {
super.onCreate(radioPlayer);
setContentView(R.layout.main);
Thread splash= new Thread(){
public void run(){
try{
sleep(3000);
startActivity(new Intent("com.test.MAINMENU"));
} catch (InterruptedException e) {
e.printStackTrace();
}
finally {
finish();
}
}
};
splash.start();
}