Skip to content
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

ViewModel from View instead of Activity or Fragment #4

Closed
GSala opened this issue Feb 10, 2018 · 1 comment
Closed

ViewModel from View instead of Activity or Fragment #4

GSala opened this issue Feb 10, 2018 · 1 comment

Comments

@GSala
Copy link

GSala commented Feb 10, 2018

When trying to encapsulate some behavior in a View instead of an Activity or a Fragment, I do not have access to the ViewModelProvider. What would be the mot appropriate way of having the same architecture when using Views?

I can see at least 4 options.

  1. Pass the ViewModelProvider as an argument to the View constructor
  2. Pass the already obtained ViewModel as an argument to the View constructor
  3. Pass a LifecycleOwner as an argument to the View constructor
  4. Hold the ViewModel in the containing Fragment/Activity and expose events from the view and consume states.
@piotrek1543
Copy link

piotrek1543 commented Apr 14, 2019

Only third option. Check GithubSample in android-architecture-component repo for an example. Please also check: https://academy.realm.io/posts/mvc-vs-mvp-vs-mvvm-vs-mvi-mobilization-moskala/ to get to know better a role of ViewModel in Android app's architecture.

@GSala GSala closed this as completed May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants