I recently started to use MVVM
pattern with LiveData
and Room in my Android app.
In my ViewModel
I fetch data from db using AsyncTask
.
But sometimes I load from db some more heavy stuff(like list with few thousands items). Normally I would add a ProgressDialog to AsyncTask, start it in onPreExecute method and close it in onPostExecute. But ProgressDialog needs a Context
:
new ProgressDialog(Context ctx)
I've read about separation between View ( Activity
) and ViewModel
and that I should not use activities context in ViewModel
classes. So how can I achieve that without having the activity context in my ViewModel
?
Maybe I should use a different approach?