Comments (6)
Looks like @wisnukurniawan has a point @alphamu please reopen this issue.
Also on your blog post on Medium @JoseAlcerreca has suggested few points to consider in the implementation.
Following his [this blogpost for Do & Dont's in MVVM] (https://medium.com/androiddevelopers/viewmodels-and-livedata-patterns-antipatterns-21efaef74a54) your pattern breaks few of the MVVM rules.
from android-mvvm-databinding-formexample.
You're both right, not just views, but also the Listeners were a bad decision the Listeners have a reference to the viewmodel as the listeners are annonymous inner classes, meaning the listener is no GC'd and thus the View is not GC'd, the View has a reference to Context so the whole activity is not GC'd...
I've known of it for a while, it was a poor decision.
I'll fix it at some point, but I don't have the free time at the moment to re-implement it.
Thanks for bringing it to my attention.
from android-mvvm-databinding-formexample.
Thanks for a quick reply, hope you'll refactor it soon, @alphamu do you have any article/tutorial which I can refer for the right way of implementing validation on form in MVVM pattern?
from android-mvvm-databinding-formexample.
Well, the fastest change to make would be to move the focus listeners to the activity and pass them into the data binding and that should fix most of the issues. A fancier way would be to create a custom binding that takes a custom focus listener and calls a function in your ViewHolder, something like app:onFocus='(view, focus)->viewHolder.onUsernameFocus(focus)'
Or you can even set a value in live data that way.
Hope this helps, in on my phone so it's really hard to go into more detail.
from android-mvvm-databinding-formexample.
I think the Google guy is getting at the fact that if you just do 2 way binding and listen for tact change, you don't need a focus listener and can use mediatedlivedata to see how the data changes and react from there.
from android-mvvm-databinding-formexample.
Okay, after having thought about this.
I don't see a problem with the code.
The ViewModel has a reference to the OnFocusChangeListener, but the OnFocusChangeListener does not have a reference to the View (the view passes itself in, we never retain a reference to it).
So, when the activity is GC'd the View can be garbage collected because the while the OnFocusChangeListener has reference to the ViewModel, it does not have a reference to the View.
The View has a reference to OnFocusChangeListener, so if the Activity is destroyed (unreachable), the activity has no reference, the View's it holds are not reachable because the ViewModel and the OnFocusChangeListener do not have reference to them.
If I'm missing something here, please tell me what it is.
from android-mvvm-databinding-formexample.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-mvvm-databinding-formexample.