1. 程式人生 > >Android中判斷應用是否第一次開啟

Android中判斷應用是否第一次開啟

    通常應用都會有這種情況:首次安裝應用第一次開啟會進入應用的嚮導頁,如果退出應用後再次進入(第二次進入),則不會進入嚮導頁會進入其他介面,下面來通過sharedpreferences實現:

1、MainActivity

@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//判斷是否第一次進入。注:除非清空應用資料或者解除安裝軟體重新安裝才能再次進入第一次
		date();
	}

	private void date() {
		SharedPreferences shared=getSharedPreferences("is", MODE_PRIVATE);
		boolean isfer=shared.getBoolean("isfer", true);
		Editor editor=shared.edit();
		if(isfer){
			//第一次進入跳轉
			Intent in=new Intent(MainActivity.this,oneActivity.class);
			startActivity(in);
			finish();
			editor.putBoolean("isfer", false);
			editor.commit();
		}else{
			//第二次進入跳轉
			Intent in=new Intent(MainActivity.this,twoActivity.class);
			startActivity(in);
			finish();


		}
	}

2017.7.4更新: