2011-07-09 39 views

回答

2

你可以保存在首選項。以下代碼打開首選項,獲取存儲在其中的次數,並將其增加。

SharedPreferences preferences = getPreferences(MODE_PRIVATE); 
int times = preferences.getInt("openKey", 0); 
preferences.edit().putInt("openKey", times+1).commit(); 

您可以在您的activity的onCreate方法中調用此代碼。

1

您可以使用SharedPreferences對象來存儲和獲取有關您的應用程序的任意信息。

使用Context.getSharedPreferences方法獲取此對象的實例。

編輯使用edit方法得到editor。完成後請不要忘記撥打commit

重要提示:如果用戶卸載應用程序的首選項走開(只是要記住....)