私のApplicationクラスには、次のものがあります。
public void loadPrefs(){
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Boolean soundValue = sharedPrefs.getBoolean("SOUND", false);
}
public void savePrefs(String key, boolean value){
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Editor edit = sharedPrefs.edit();
edit.putBoolean(key, value);
edit.commit();
}
私が知る限り、そこはすべて大丈夫です。
現在、SurfaceViewを拡張するメインクラスには、次のものがあります。
myApp mySettings = (myApp)getContext().getApplicationContext();
次に、次のように値を保存できます:(再びsurfaceViewアクティビティから)
myPlanSettings.savePrefs("SOUND", false);}
ただし、私が理解できないのは、値を読み戻して、次のようにローカル変数を設定できるようにする方法です。
Boolean thisValue = (the value from the shared preferences).
助けてくれてありがとう