2013-08-21 34 views

回答

2

您可以將值保存到SharedPreferences:

SharedPreferences mPreferences = getSharedPreferences("CurrentUser", 
      MODE_PRIVATE); 

爲了節省:

SharedPreferences.Editor editor = mPreferences.edit(); 
editor.putInt("personalRecord", 30); 
editor.commit(); 

要檢索:

mPreferences.getInt("personalRecord", defaultValue); 
0

使用SharedPreferences
試試這個代碼。

 int count = 2; 
     boolean bool = true; 
     SharedPreferences preferences = getSharedPreferences("key", 0); 
     SharedPreferences.Editor editor = preferences.edit(); 
     editor.putInt("int", count); 
     editor.putBoolean("bool", bool); 
     editor.commit(); 


SharedPreferences

 SharedPreferences preferences = getSharedPreferences("key", 0); 
     int count = preferences.getInt("int",0); 
     boolean bool = preferences.getBoolean("bool",false);