title: How to combine two live data one after the other?
body: <p>I have next use case: User comes to registration form, enters name, email and password and clicks on register button. After that system needs to check if email is taken or not and based on that show error message or create new user...</p>
  
  <p>I am trying to do that using Room, ViewModel and LiveData. This is some project that on which I try to learn these components and I do not have remote api, I will store everything in local database</p>
  
  <p>So I have these classes:</p>
  
  <ul>
  <li>RegisterActivity</li>
  <li>RegisterViewModel</li>
  <li>User</li>
  <li>UsersDAO</li>
  <li>UsersRepository</li>
  <li>UsersRegistrationService</li>
  </ul>
  
  <p>So the idea that I have is that there will be listener attached to register button which will call <code>RegisterViewModel::register()</code> method.</p>
  
  <pre><code>class RegisterViewModel extends ViewModel {
  
      //...
  
      public void register() {
          validationErrorMessage.setValue(null);
          if(!validateInput())
              return;
          registrationService.performRegistration(name.get(), email.get(), password.get());
      }
  
      //...
  
  }
  </code></pre>
  
  <p>So that is the basic idea, I also want for <code>performRegistration</code> to return to me newly created user.</p>
  
  <p>The thing that bothers me the most is I do not know how to implement <code>performRegistration</code> function in the service</p>
  
  <pre><code>class UsersRegistrationService {
      private UsersRepository usersRepo;
  
      //...
  
      public LiveData&lt;RegistrationResponse&lt;Parent&gt;&gt;  performRegistration(String name, String email, String password) {
           // 1. check if email exists using repository
           // 2. if user exists return RegistrationResponse.error("Email is taken") 
           // 3. if user does not exists create new user and return RegistrationResponse(newUser)
      }
  }
  </code></pre>
  
  <p>As I understand, methods that are in <code>UsersRepository</code> should return LiveData because <code>UsersDAO</code> is returning LiveData</p>
  
  <pre><code>@Dao
  abstract class UsersDAO { 
      @Query("SELECT * FROM users WHERE email = :email LIMIT 1")
      abstract LiveData&lt;User&gt; getUserByEmail(String email);
  }
  
  class UsersRepository {
      //...
      public LiveData&lt;User&gt; findUserByEmail(String email) {
          return this.usersDAO.getUserByEmail(email);
      }
  }
  </code></pre>
  
  <p>So my problem is how to implement <code>performRegistration()</code> function and how to pass value back to view model and then how to change activity from RegisterActivity to MainActivity...</p>