→ Device file explore에서 찾는다.
private lateinit var sharedPreferences : SharedPreferences
private lateinit var editor: SharedPreferences.Editor
override fun onCreate(savedInstanceState: Bundle?){
sharedPreferences = getSharePreferences("loginInfo", MODE_PRIVATE)
editor = sharedPreferences.edit()
}
binding.checkboxLoginInfo!!.isChecked =
sharedPreferences.getBoolean(getString(R.string.auto_login).false)
binding.userid!!.setText(sharedPreferences.getString(getString(R.string.auto_login_id),""))
binding.password.setText(sharedPreferences.getString(getString(R.string.auto_login_password),""))
//get 뒤에 key값과 defaultValue 두 가지를 써야하는데
// key 값이 null일 경우 반환할 defaultValue 값을 지정해주는 것이다.
if(binding.checkboxSaveLoginInfo!!.isChecked){
editor.putString(
getString(R.string.auto_login_id),
binding.userid!!.text.toString()
)
editor.putString(
getString(R.string.auto_login_password),
binding.password.text.toString()
)
editor.commit()
}else{
editor.putString(getString(R.string.auto_login_id),"")
editor.putString(getString(R.string.auto_login_password),"")
editor.commit()
}