[kotlin] SharedPreferences

loci·2023년 4월 21일

andriod

목록 보기
12/19

간단한 데이터를 저장하고 불러올 수 있다.

앱을 꺼도 유지가 되기 때문에 간단한 데이터베이스 역할을 할 수 있다.

key, value 형태로 xml파일로 저장되고 앱을 삭제할 때 까지 유지된다.

val sharedPreference = getSharedPreferences("number", 0) //저장파일명, 접근권한
val editor = sharedPreference.edit() 

val count = sharedPreference.getInt("count", 0) // 저장된 값을 불러온다 getString, getBoolean 등 사용가능

editor.putInt("count", count) // 값을 저장한다 apply()까지 해주어야 함
editor.apply()
profile
편리한 개발자

0개의 댓글