title: Live Data is getting called multiple times?
body: <p>I'm using <code>Android Architecture Components</code> in my App.  In My Login Activty,     I'm showing a Dialog when the login is failed!</p>
  
  <p>Due to Live Data, the dialog has been showing over 3 times. I added some logs &amp; discovered that the <code>livedata</code> is called multiple times.</p>
  
  <p>How can I Fix this Issue ?</p>
  
  <p><strong>ACTIVITY</strong></p>
  
  <pre><code>mViewModel.authenticate(token, binding.inputPassword.getText().toString()).observe(LoginActivity.this, apiResponse -&gt; {
      progress.dismiss();
      if (apiResponse != null) {
          if (apiResponse.getError() != null) {
              Log.e("Login", "Network Failure");
          } else {
              if (apiResponse.getAuthuser().getStatus().equals("VALID")) {
                  PrefUtils.saveUserToPrefs(LoginActivity.this, apiResponse.getAuthuser());
                  finish();
              } else if (apiResponse.getAuthuser().getStatus().equals("INVALID")) {
                  Log.e("LOGIN Issue ", "Showing Dialog" + apiResponse.getAuthuser().getStatus());
                  loginFailure();
              }
          } 
      }
  });
  </code></pre>
  
  <p><strong>ViewModel</strong></p>
  
  <pre><code>class LoginActivityViewModel extends ViewModel {
  
      private final FarmerRepository farmerRepository;
      private MediatorLiveData&lt;ApiResponse&gt; mApiResponse;
  
      LoginActivityViewModel(FarmerRepository repository) {
          mApiResponse = new MediatorLiveData&lt;&gt;();
          farmerRepository = repository;
      }
  
      MediatorLiveData&lt;ApiResponse&gt; authenticate(String encryptedMobile, String pwd) {
          mApiResponse.addSource(
                  farmerRepository.authenticate(encryptedMobile, pwd),
                  apiResponse -&gt; mApiResponse.setValue(apiResponse)
          );
          return mApiResponse;
      }
  }
  </code></pre>
  
  <p><strong>LOGCAT</strong></p>
  
  <pre><code>11-01 00:13:31.265 24386-24386 E/LOGIN Issue: Showing DialogINVALID
  
  11-01 00:13:31.312 24386-24386 E/LOGIN Issue: Showing DialogINVALID
  11-01 00:13:37.034 24386-24386 E/LOGIN Issue: Showing DialogINVALID
  
  11-01 00:13:38.196 24386-24386 E/LOGIN Issue: Showing DialogINVALID
  11-01 00:13:38.234 24386-24386 E/LOGIN Issue: Showing DialogINVALID
  11-01 00:13:38.273 24386-24386 E/LOGIN Issue: Showing DialogINVALID
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After using SingleLiveEvent. It is not being observed. Can you tell me what is wrong with the code ? </p>
  
  <p><strong>Updated ViewModel</strong></p>
  
  <pre><code>class LoginActivityViewModel extends ViewModel {
  
      private final FarmerRepository farmerRepository;
      private MediatorLiveData&lt;ApiResponse&gt; mApiResponse;
  private SingleLiveEvent&lt;ApiResponse&gt; mMsgUpdate;
  
      LoginActivityViewModel(FarmerRepository repository) {
          mApiResponse = new MediatorLiveData&lt;&gt;();
          farmerRepository = repository;
      mMsgUpdate = new SingleLiveEvent&lt;&gt;();
      }
  
      SingleLiveEvent&lt;ApiResponse&gt; authenticate(String encryptedMobile, String pwd) {
          mApiResponse.addSource(
                  farmerRepository.authenticate(encryptedMobile, pwd),
                  apiResponse -&gt; mMsgUpdate.setValue(apiResponse)
          );
          return mMsgUpdate;
      }
  }
  </code></pre>