I know that one of the solutions to handle orientation change is to use ViewModel to hold the data as it outlives the activity.
However, I was wondering, can't we achieve the same thing if we create a static variable in the class to hold the same data?
Why would we go down the ViewModel path?
Thanks
One reason is because Activities themselves aren't static or singletons. You can have an ItemViewActivity launch another ItemViewActivity for a different item, and if they're sharing the same variables via statics you've probably just broke the back button. And if you don't code them very carefully you're probably going to send data to the wrong Activity's views.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With