本文實例為大家分享了Android判斷程序是否第一次啟動的具體代碼,供大家參考,具體內容如下
public class Welcome extends Activity { private final long SPLASH_LENGTH = 2000; Handler handler = new Handler(); public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.farst_img); //定義一個setting記錄APP是幾次啟動!!! SharedPreferences setting = getSharedPreferences("com.example.hr_jie", 0); Boolean user_first = setting.getBoolean("FIRST", true); if (user_first) {// 第一次則跳轉到歡迎頁面 setting.edit().putBoolean("FIRST", false).commit(); tiaozhuanzhu(); } else {//如果是第二次啟動則直接跳轉到主頁面 tiaozhuanfu(); } } public void tiaozhuanzhu(){ handler.postDelayed(new Runnable() { //使用handler的postDelayed實現延時跳轉 public void run() { Intent intent = new Intent(Welcome.this, Welcome_four.class); startActivity(intent); finish(); } }, SPLASH_LENGTH);//2秒后跳轉至應用主界面MainActivity } public void tiaozhuanfu(){ handler.postDelayed(new Runnable() {//使用handler的postDelayed實現延時跳轉 public void run() { Intent intent = new Intent(Welcome.this, MainActivity.class); startActivity(intent); finish(); } }, SPLASH_LENGTH);//2秒后跳轉至應用歡迎界面}}以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答