你好,我想一個默認後顯示的其它閃屏,如果應用程序首次啓動時間(例如安裝後右)閃屏 - 與共享偏好
第一時間,所以我寫了這個。但是新的活動不會啓動,它停留在啓動屏幕上。有人可以說它有什麼問題嗎?
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();
}
}
}
謝謝。
您確定您在調用的活動中調用了setContentView嗎? – Guardanis
是的。這不應該是問題 – Ahmad