SharedPreferences라는 인터페이스는 ContextWrapperd의 getSharedPreferences에서 반환된 환경 설정등의 값을 공유하는 단일 인스턴스이다. 해당 환경 설정값에 대한 수정은 SharedPreferences.Editor를 통해 이루어진다.
SharedPreferences spf = getSharedPreferences("MODE", 0); int mode = spf.getInt("mode", 0);
Retrieve all values from the preferences.
|
|
Retrieve a boolean value from the preferences.
|
|
Retrieve a float value from the preferences.
|
|
Retrieve an int value from the preferences.
|
|
Retrieve a long value from the preferences.
|
|
Retrieve a String value from the preferences.
|
위의 메소드들을 이용하여 원하는 데이터들을 가져 올 수 있다. key에는 변수명이 들어가며 defValue에는 해당 키가 존재하지 않을때 기본적으로 설정 할 값을 넣어준다.
int mode = 1; SharedPreferences.Editor edit = spf.edit(); edit.putInt("mode", mode); edit.commit();
값을 수정할 때는 위와같은 형태로 해주면 되겠다...