title: How ViewModel state is automatically updated
body: <p>In an activity, I declared a chronometer  </p>
  
  <pre><code>Chronometer chronometer = findViewById(R.id.timer);
  
  ChronometerViewModel viewModel = ViewModelProviders.of(this).get(ChronometerViewModel.class);
  if (viewModel.getStartTime() == null) {
     long startTime = SystemClock.elapsedRealtime();
          viewModel.setStartTime(startTime);
          chronometer.setBase(startTime);
      } else {
          chronometer.setBase(viewModel.getStartTime());
      }
   chronometer.start();
  </code></pre>
  
  <p>ViewModel class</p>
  
  <pre><code>public class ChronometerViewModel extends ViewModel {
    @Nullable
    private Long mStartTime;
  
    @Nullable
    public Long getStartTime() {
      return mStartTime;
    }
  
    public void setStartTime(final long startTime) {
      this.mStartTime = startTime;
    }
  }
  </code></pre>
  
  <p>When I rotated the screen, chronometer automatically resumes from the previous state. But I did not write any code which stores the current state of the timer to ViewModel class on configuration change. How is the state automatically restored?</p>
  
  <p>I am following this google's codelabs <a href="https://codelabs.developers.google.com/codelabs/android-lifecycles/index.html#2" rel="nofollow noreferrer">tutorial</a> </p>
  
  <p>Edit: I was confused with the setBase method of Chronometer. I assumed that my state variable, mStartTime is automatically getting updated to current time that was showing in Chronometer widget. Now I have checked the documentation of setBase method. since mStartTime persists on confirguration change, we can use old value from which Chronometer has started. So Chronometer actually resumes.</p>