본문 바로가기
반응형

jetpack10

Android - DataStore로 SharedPreferences를 대체하자. 어플리케이션을 개발하다보면 앱 내부에 데이터를 저장해야 할 때가 있다. 그 중에서 어떤 유저가 특정 기능을 활성화 했는지 여부와 같이 굉장히 작은 규모의 데이터가 저장되어야 할 때가 있다. 이럴때 우린 SharedPreferences를 사용해서 저장하곤 했다. 하지만 SharedPreferences는 여러가지 단점이 있다. UI쓰레드에서 호출하기에 안전하지 않고, 예외나 런타임 안정성 등이 있다. 그리고 비동기 API에 대한 대응도 부족한 편이다. 이런 단점 때문인지, 구글에서 이를 보완하기 위해 Jetpack DataStore를 개발하였다. https://developer.android.com/topic/libraries/architecture/datastore?hl=ko 앱 아키텍처: 데이터 영역 -.. 2023. 7. 7.
Android - Deep dive into LiveData - 4. MediatorLiveData 이전 포스팅에서 Transformations를 사용하여 LiveData를 다른 LiveData로 변화시켰다. 이번 포스팅은 Transformations 내부에서 사용한 MediatorLiveData에 대해 알아본다. https://developer.android.com/reference/android/arch/lifecycle/MediatorLiveData MediatorLiveData | Android Developers Stay organized with collections Save and categorize content based on your preferences. The android.arch Architecture Components packages are no longer maintain.. 2023. 4. 1.
Android - Deep dive into LiveData - 3. Transformations(map, switchMap) LiveData를 사용할 때 LiveData가 변경되었을 때 값을 수신하고 다른 형태의 데이터로 변환해야 하는 경우가 있다. 예를들면 아래와 같은 상황을 보자. data class User( val firstName: String, val lastName: String, val nickName: String, ... ) private val _userLiveData: MutableLiveData = MutableLiveData() User 객체를 얻어왔을 때, UI에는 firstName과 lastName만을 수신해야한다고 가정해보자. Activity/Fragment에서 User를 UI에서 가공해야 할까? 이는 바람직하지 않다. 왜냐하면 데이터의 가공은 ViewModel 레이어에서 이루어지고, UI는 단지.. 2023. 1. 28.
Android - Deep dive into LiveData - 2. setValue vs postValue LiveData를 사용할 때, 데이터의 변경은 어떻게 할 수 있을까? 제목에도 나와있듯이, setValue와 postValue가 있다. 왜 두 가지 방법이 있을까? 무슨 차이가 있는지 알아보자. public abstract class LiveData { ... /** * Sets the value. If there are active observers, the value will be dispatched to them. * * This method must be called from the main thread. If you need set a value from a background * thread, you can use {@link #postValue(Object)} * * @param value .. 2023. 1. 21.