ViewModel vs Activity member variable?

122
February 15, 2021, at 08:20 AM

Going by this image, the lifecycle of a ViewModel is pretty much like that of an Activity instance, so why not just use an activity instance variable? Is a ViewModel better because of the automatic call to onClear? Or because it is observable (in which case why not just have observable, normal member variables)?

Answer 1

Maybe the graphic is not clear enough but the printed lifecycle hooks are from the activity, the viewmodel remains the same until the activity is completely finished.

So, a variable in the activity instance would be released after rotation for example as that activity instance is going to be destroyed while a new activity instance is created. But this would not happen if it's on the ViewModel as both would use the same one.

READ ALSO
UnicodeError 'idna' encoding when working with Heroku, Redis and Flask

UnicodeError 'idna' encoding when working with Heroku, Redis and Flask

I have a Flask REST API hosted on Heroku with a Heroku-Redis server

158
Why is this happening? I'm getting correct display in console output and right amount of rows in UI but I'm getting no outputs

Why is this happening? I'm getting correct display in console output and right amount of rows in UI but I'm getting no outputs

So I have this problem with displaying phone numbers for userConsole output is displaying numbers, and my user interface is displaying the right amount of rows but not numbers themselves

143
Find similar news on SQL based on similar tags

Find similar news on SQL based on similar tags

I have a list of news from a few newspapers(Getting them from a RSS feed)Let's say every newspaper returns a list of news with tags

134
Update data only if user change anything in laravel

Update data only if user change anything in laravel

Update data only if the user changes anything otherwise return a message that nothing to updateAfter click the edit button, if the user hits update button without change anything then return message nothing to update

137