-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caution: A ViewModel must never reference a view, Lifecycle, or any class that may hold a reference to the activity context. #65
Comments
I am trying to implement MVVM in my current project. I was searching for some references. I just to clear a few doubts. So you can correct me if I am wrong. mLoginViewModel.setNavigator(this); This line of code is actually passing on the reference of the current activity to that viewmodel. But as per documentation, Caution: A ViewModel must never reference a view, Lifecycle, or any class that may hold a reference to the activity context. I am also searching for an approach of handling errors thrown by the API. I'd be glad if you can guide me through. Thanks |
@ameybhandarkar the navigator is an interface between the activity and the viewmodel. That is not holding a reference to a context or really anything. There is a special kind of viewmodel called the AndroidViewModel that does hold reference to a context. |
@clj0020 It holds a reference to the object that implements the interface, in this case the activity. There are better ways to notify the UI, try using |
@ameybhandarkar have idea for replace Weak references in ViewModel i create
////////////////////////////// |
|
just corrected something 👍🏿 |
https://github.com/MindorksOpenSource/android-mvvm-architecture/blob/595acd0c79a4a7a51594cbc88071f85f266f26ff/app/src/main/java/com/mindorks/framework/mvvm/ui/login/LoginActivity.java#L91
The text was updated successfully, but these errors were encountered: