https://github.com/GO-SOPT-ANDROID/sangho-kim
로그인에 성공했을 경우 그 이후에 앱을 들어올 때부터 자동로그인이 될 수 있게 설정
로그인 액티비티에서 전역으로 SharedPreference와 editer 객체 생성해두기
sharedPreferences = getSharedPreferences("loginInfo", MODE_PRIVATE)
editor = sharedPreferences.edit()
로그인 성공했을 시, 액티비티 이동 전에 SharedPreference에 값 저장
editor.putString("id", id)
editor.putString("pw",pw)
editor.apply()
로그인 액티비티 실행 시, SharedPreference에 저장되어 있는 값이 있는지 확인해보고 (성공한 로그인이 있다는 뜻) 있다면 바로 다음 액티비티 실행
val idShared = sharedPreferences.getString("id", null)
val pwShared =sharedPreferences.getString("pw", null)
if (idShared != null && pwShared != null) {
Log.d("sangho", "sharedPreference -> id=$idShared, pw=$pwShared")
val intent = Intent(this, MyPageActivity::class.java).apply {
putExtra("id", idShared)
putExtra("pw", pwShared)
}
Toast.makeText(this, "자동 로그인에 성공하였습니다.", Toast.LENGTH_SHORT).show()
startActivity(intent)
}