일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- Android
- kotlin
- nav_graph
- 스플래시
- room
- TypeConverter
- ViewModel
- 일렉트론
- Safe Args
- Binding Adapter
- recyclerview
- Jetpack Compose
- hilt
- 취업
- 주석
- 개발자
- 테마
- 면접
- asLiveData()
- BottomNavigationView
- fragment
- Livedata
- electron
- android studio
- themes.xml
- Navigation Component
- 안드로이드
- imageview
- Gradle
- Datastore
Archives
- Today
- Total
나만 보는 일기장
[DataStore] DataStore 싱글톤으로 쓰기 본문
java.lang.IllegalStateException: There are multiple DataStores active for the same file: [...] You should either maintain your DataStore as a singleton or confirm that there is no two DataStore's active on the same file (by confirming that the scope is cancelled).
로그인 기능을 구현할 때 메인 액티비티에서 DataStore에 접근해 저장된 토큰값이 있는지 확인하고 없으면 로그인 화면으로 넘기는 방식을 구현하려 했는데,
로그인을 처리하는 액티비티에서도 DataStore를 사용해서 그런지 로그인 화면으로 넘어갈 때 DataStore 객체가 여러 개 존재한다는 Exception이 발생했습니다.
이를 해결하기 위해서 DataStore를 싱글톤으로 관리하라고 했는데, 검색해보니 그 방법은 아주 쉬웠습니다.
DataStore 객체를 파일의 최상단으로 옮겨주면 간단히 싱글톤으로 사용할 수 있다고 합니다.
해당 글 링크
DataStore | Android 개발자 | Android Developers
DataStore 비동기적이고 일관된 트랜잭션 방식으로 데이터를 저장하여 SharedPreferences의 일부 단점을 극복합니다. 최근 업데이트 현재 안정화 버전 다음 버전 후보 베타 버전 알파 버전 2021년 8월 4일
developer.android.com
'개발 > Android' 카테고리의 다른 글
Comments