Search code examples
androidmvvmandroid-contentproviderandroid-room

Query MediaStore.Audio.Media using Android Architecture components?


I have been looking at Android Architecture Components LiveData, Room and ViewModel (MVVM). It saves us the hassle of using loaders and monitoring our data on our database tables. But I'm trying to find out if we can use LiveData and this architecture to query Medistore.Audio.Media and other such Uri's provided via ContentProviders.


Solution

  • Room works with SQLite, not other sources of data, such as a ContentProvider.

    There should be nothing stopping you from creating a ProviderLiveData that uses a background thread, a ContentResolver, and even a ContentObserver, to retrieve and keep updated some data retrieved from a ContentProvider. Similarly, a ViewModel could hold a Cursor, or a ProviderLiveData.