Preference Example
SharedPreference 기본 선언 형태는 다음과 같다.
SharedPreferences pref = getSharedPreferences("isTrue", MainActivity.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); |
MODE_PRIVATE는 파일 생성 모드이며 기본값이다. 해당 파일은 호출한 앱에서만 접근이 가능하다.
pref.getBoolean("isTrue", false); |
저장된 데이터를 가져오는 방법.
editor.putBoolean("isTrue", true); editor.commit(); |
데이터를 저장하는 방법.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> </LinearLayout> |
MainActivity.java
package com.preferenceexam.mystoryg.preferenceexam; } |
'프로그래밍 > Android' 카테고리의 다른 글
알람 예제 (AlarmManager Example) (0) | 2016.12.22 |
---|---|
브로드캐스트 리시버 (BroadcastReceiver Example) (0) | 2016.12.20 |
알림 예제(Notification Example) (0) | 2016.12.20 |
Service Example (0) | 2016.12.17 |
명시적 인텐트(Explicit Intent) (0) | 2016.12.16 |
암시적 인텐트(Implicit Intent) (0) | 2016.12.15 |
WebView 줄바꿈 문제 (0) | 2016.02.18 |