title: Android dev, What's best practice for timing update data in viewmodel
body: <p>I want obey the <code>MVVM</code> struct in an android app. Now I have a situaion:</p>
  <p>I want repeat get data from net and update the view.</p>
  <p>So my code is like this:</p>
  <pre class="lang-java prettyprint-override"><code>public class FooVm() {
      private MutalbeLiveData&lt;Data&gt; data = new MutableLiveData();
      private Timer timer;
      
      public LiveData&lt;Data&gt; getData() {
          if (data == null) {
              data = new MutableLivedata();
              repeatRefresh()
          }
      }
  
      private void repeatRefersh() {
        timer = new Timer();
        // schedule at fixed rate get data from net.
      }
  
      @override
      public void onClear() {
          if (timer == null) {
              timer.cancel();
              timer = null;
          }
      }
  }
  </code></pre>
  <p>Now question is: if I want pause refresh when then view(for example, an Activity) onStop and resume refresh when view onStart. What's the right way to do thi?</p>