title: How can we "assign" LiveData from Room to MutableLiveData, within ViewModel
body: <p>Recently, I am stuck with the following code.</p>
  
  <pre><code>public class NoteViewModel extends ViewModel {
  
      private final MutableLiveData&lt;List&lt;Note&gt;&gt; notesLiveData = new MutableLiveData&lt;&gt;();
  
      public NoteViewModel() {
          LiveData&lt;List&lt;Note&gt;&gt; notesLiveDataFromRepository = NoteRepository.INSTANCE.getNotes();
  
          // How can I "assign" LiveData from Room, to MutableLiveData?
      }
  
  }
  </code></pre>
  
  <p>I was wondering, how can I "assign" <code>LiveData</code> from <code>Room</code>, to <code>MutableLiveData</code>? </p>
  
  <p>Using <code>Transformation.map</code> and <code>Transformation.switchMap</code> wouldn't work, as both returns <code>LiveData</code>, not <code>MutableLiveData</code>.</p>
  
  <hr>
  
  <h2>Possible workaround</h2>
  
  <p>One of the possible solution is that, instead of</p>
  
  <pre><code>@Dao
  public abstract class NoteDao {
      @Transaction
      @Query("SELECT * FROM plain_note")
      public abstract LiveData&lt;List&lt;Note&gt;&gt; getNotes();
  </code></pre>
  
  <p>I will use</p>
  
  <pre><code>@Dao
  public abstract class NoteDao {
      @Transaction
      @Query("SELECT * FROM plain_note")
      public abstract List&lt;Note&gt; getNotes();
  </code></pre>
  
  <p>Then, in my <code>ViewModel</code>, I will write</p>
  
  <pre><code>public class NoteViewModel extends ViewModel {
      private final MutableLiveData&lt;List&lt;Note&gt;&gt; notesLiveData = new MutableLiveData&lt;&gt;();
  
      public NoteViewModel() {
          new Thread(() -&gt; {
              List&lt;Note&gt; notesLiveDataFromRepository = NoteRepository.INSTANCE.getNotes();
              notesLiveData.postValue(notesLiveDataFromRepository);
          }).start();
      }
  
  }
  </code></pre>
  
  <p>I don't really like this approach, as I'm forced to handle threading thingy explicitly.</p>
  
  <p>Is there a better way, to avoid handling threading explicitly?</p>