여기에 Activity
에서 환경 설정을 저장하고로드하려는 경우 매우 빠른 샘플입니다.
환경 설정에서 값을 저장하려면 다음 "best_score"
는 당신이 값을 저장하기 위해 안드로이드를 이야기하는 아래의 열쇠입니다
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
if (sharedPreferences.contains("best_score")) {
// we have a high score saved, load it...
int numberOfPoints = sharedPreferences.getInt("best_score", -1);
// here you'd like to do something with the value, for example display it.
} else {
// there is no high score value - you should probably hide the "best score" TextView
}
- 그것은 아무것도 될 수 있습니다
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("best_score", numberOfPoints);
editor.commit();
이 값을로드하려면 하지만, 동일한 값에 액세스/조작하려는 때마다 키가 동일해야합니다 (예 : "최고 점수").
sharedpreferences에 대해 들어 본 적이 있다면, 그들에 대해 Google보다 여기에서 물어 보는 것이 정말 쉬운가요? 첫 번째 페이지에는 6 개의 튜토리얼이 있습니다. –