您好,如果应用程序第一次启动(例如在安装后),我想在默认屏幕之后显示另一个启动屏幕
所以我写了这个。但是新的 Activity 没有启动它停留在 Splash 屏幕上。有人可以说它有什么问题吗?
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.TextView;
public class splash extends Activity {
private Thread splashTread;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("firstTime", false)) {
// run your one time code
Intent i = new Intent(splash.this, main.class);
startActivity(i);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("firstTime", true);
editor.commit();
// thread for displaying the SplashScreen
splashTread = new Thread() {
@Override
public void run() {
try {
synchronized(this){
//wait 2 sec
wait(2000);
}
} catch(InterruptedException e) {}
finally {
finish();
//start a new activity
Intent i = new Intent();
i.setClass(splash.this, main.class);
startActivity(i);
stop();
}
}
};
splashTread.start();
}
}
}
谢谢。