androidandroid-contentproviderandroid-loadermanagerandroid-loader

LoaderCallbacks implemented by a Standalone class that acts as datasource


I am writing a music player. I'm following MVVM. So the fragmentA needs a list of songs. This fragment calls a method in ViewModelClass that in turn uses a standalone class (implementing LoaderCallbacks) and returns a list of song. This fragment can delete a song from the list and it wants to get the new/updated list also. So I have two questions:

1) Should activity implement loadercallbacks itself? Would it be better? As per design considerations?

2) How should deletion be done? Should Standalone class have a method for song deletion? Or should activity be implementing the LoaderCallbacksitself and a DAO like class have method for song deletion?


Solution

  • Try using ContentOberver. This will give you callback whenever your dataset have change. Refer this link