Ive Vasiljevic
03/05/2019, 9:52 AMAlhima
03/05/2019, 10:35 AMJiddles
03/05/2019, 11:24 AMBino
03/05/2019, 11:29 AMNO!
⚠️ Never put an activity context inside a viewmodel.
a toast is an element of the view and should be paced in it. You can use a singleEvent like showMessage
and show a toast in the regarding view.
There are only rare situations, where you can use a context in the viewmodel eg. for android libraries or persistence. It is recommended to use the applicationContext
instead to prevent leaks.
https://developer.android.com/reference/android/arch/lifecycle/AndroidViewModel.html