Architecture ViewModel — a half baked solution?

Elye - A One Eye Dev By His Grace
The Startup
Published in
3 min readSep 30, 2019

--

Architecture component is the way recommended by Google. It’s an MVVM approach, where it’s supposed to provide 3 solutions as below.

If you are unfamiliar with Architecture Component, you could refer to this simple tutorial, Architecture for Dummies.

  1. The LiveData — Where our activity/fragment will listen to for new data provided by the ViewModel (or any helper class you made). It is basically a minimal version of RxJava, but does know about the activity/fragment’s lifecycle. This delinks the
  2. The LifecycleObserver — Once a class implements it, the function that is annotated with appropriate @OnLifecycleEvent will be triggered upon the respective life cycle
  3. The ViewModel — This is suppose to be the an object that outlive the Activity/Fragment, where onConfiguration change, the state it is in, is retained. Hence giving an impression we no longer need to save state anymore.

LiveData and LifecycleObserver is great as it decouple the ViewModel from the Activity/Fragment, yet having them related.

The half baked ViewModel

--

--