title: How to constantly update livedata object from a service with viewmodel in MVVM?
body: <p>I am trying to constantly update the UI based on a long-running service output.
  Basically, I want to display and append a list of users one by one after they get processed by the bound service.</p>
  
  <p><b>MainActivityViewModel</b></p>
  
  <pre><code>public class MainActivityViewModel extends ViewModel {
  
      private MutableLiveData&lt;User&gt; user = new MutableLiveData&lt;&gt;();
  
      private MutableLiveData&lt;MyService.MyBinder&gt; mBinder = new MutableLiveData&lt;&gt;();
      private ServiceConnection serviceConnection = new ServiceConnection() {
          @Override
          public void onServiceConnected(ComponentName className, IBinder iBinder) {
              MyService.MyBinder binder = (MyService.MyBinder) iBinder;
              mBinder.postValue(binder);
          }
  
          @Override
          public void onServiceDisconnected(ComponentName arg0) {
              mBinder.postValue(null);
          }
      };
  
  
      public ServiceConnection getServiceConnection(){
          return serviceConnection;
      }
  
      public LiveData&lt;User&gt; getUser(){
          return user;
      }
  
      public LiveData&lt;MyService.MyBinder&gt; getBinder(){
          return mBinder;
      }
  }
  </code></pre>
  
  <p><b>My Service</b></p>
  
  <pre><code>public class MyService extends Service {
  
      private final IBinder mBinder = new MyBinder(); 
      private Handler mHandler;
  
      @Override
      public void onCreate() {
          super.onCreate();
          mHandler = new Handler();
      }
  
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return mBinder;
      }
  
      public void starFetchingUsers(User obj){
          Thread thread = new Thread(new Runnable() {
              @Override
              public void run() {
   /**********************************************************/ 
  </code></pre>
  
  <p><I>Here i will be sending POST method one by one for 100 times and will get 
  a response as a user object which needs to be a liveData. So once this object 
  is changed after next post method, i want it to get displayed or appended on UI.
  </I></p>
  
  <p><b>How to bind this dynamic user object variable to the MutableLiveData user created in MainActivityViewModel class? so this get auto updated in UI.</b></p>
  
  <pre><code>/**********************************************************/
              }
          });
  
          thread.start();
  
      }
      public class MyBinder extends Binder{
  
          MyService getService(){
              return MyService.this;
          }
  
      }
      @Override
      public void onTaskRemoved(Intent rootIntent) {
          super.onTaskRemoved(rootIntent);
          stopSelf();
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
      }
  }
  
  </code></pre>
  
  <p>Please let me know what I am missing in both classes.</p>