public class GtSharedPreferences {
public static final String NAME = "GtdSharedPrefernces";
//首頁-是否第一次使用public static final String KEY_FIRST_USED = "isFirstUsed";
public static void saveIsFirstUsed(Context context) {
SharedPreferences sp = context.getSharedPreferences(NAME, Activity.MODE_PRIVATE);
sp.edit().putBoolean(KEY_FIRST_USED, false).commit();
}
public static boolean getIsFirstUsed(Context context) {
SharedPreferences sp = context.getSharedPreferences(NAME, Activity.MODE_PRIVATE);
return sp.getBoolean(KEY_FIRST_USED, true);
}
}
MainActiviy
boolean isFirstUse = GtSharedPreferences.getIsFirstUsed(this);
if (isFirstUse) {
new AlertDialog.Builder(this)
.setTitle("123")
.setMessage("456")
.setPositiveButton("789", new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
GtSharedPreferences.saveIsFirstUsed(IndexActivity.this);
dialog.dismiss();
}
}).show();
}