私のアプリは最初の実行時にres/rawからsdcardにファイルをコピーします。それ以降のすべてのアプリのアップデートでこれらのファイルを更新したいと思う。どうすれば、すべてのアプリのアップデートでfirstrunの設定をtrueにリセットすることができますか?Android:アプリのアップデート時にFirstRun SharedPreferencesをリセットするにはどうすればいいですか?
/**
* get if this is the first run
*
* @return returns true, if this is the first run
*/
public boolean getFirstRun() {
return mPrefs.getBoolean("firstRun", true);
}
/**
* store the first run
*/
public void setRunned() {
SharedPreferences.Editor edit = mPrefs.edit();
edit.putBoolean("firstRun", false);
edit.commit();
}
SharedPreferences mPrefs;
/**
* setting up preferences storage
*/
public void firstRunPreferences() {
Context mContext = this.getApplicationContext();
mPrefs = mContext.getSharedPreferences("myAppPrefs", 0); //0 = mode private. only this app can read these preferences
}
public void setStatus(String statustext) {
SharedPreferences.Editor edit = mPrefs.edit();
edit.putString("status", statustext);
edit.commit();
}
}
感謝あなたは答えます!あまりにも多くのことを尋ねるのは嫌ですが、コードスニペットを提供できますか?私はあなたが言っていることを理解していますが、それを実装する方法を考え出すのに苦労しています... –
@ RivieraKidの回答には、私が考えていた実装の種類が含まれています。 –