title: Android MVVM - How to make LiveData emits the data it has (forcing to trigger the observer)
body: <p>I have this <code>ViewModel</code> that gets a list from the network and I populate a <code>RecyclerView</code> with the data (<code>MyAvailabilityRepository</code> returns a <code>MutableLiveData</code>, that's why i'm using <code>Transformations.switchMap</code>):</p>
  
  <pre><code>class MyAvailabilityViewModel : ViewModel() {
      private val getListsParams = MutableLiveData&lt;String&gt;()
      private val getListsObservable = Transformations.switchMap(getListsParams) { 
          organizationId -&gt; MyAvailabilityRepository.getSectionedLists(organizationId) 
      }
  
      fun getListsObservable() : LiveData&lt;Resource&lt;MutableList&lt;SectionedAvailabilityList&gt;&gt;&gt; {
          return getListsObservable
      }
  
      fun fetchLists(organizationId: String, forceRefresh: Boolean = false) {
          if (getListsParams.value == null || forceRefresh) {
              getListsParams.value = organizationId
          }
      }
  }
  </code></pre>
  
  <p>Fragment's <code>onActivityCreated</code>:</p>
  
  <pre><code>override fun onActivityCreated(savedInstanceState: Bundle?) {
      ...
      viewModel.getListsObservable().observe(this, Observer { // populate RecyclerView })
      viewModel.fetchLists(organizationId)
  }
  </code></pre>
  
  <p>Since <code>getListParams.value</code> is null the first time, it will set <code>getListsParams.value = organizationId</code> and trigger the <code>switchMap</code> and call the repository to get the list from the network.</p>
  
  <p>When I want to force a refresh (by pull-to-refresh) and call the network again, I can use <code>forceRefresh = true</code>:</p>
  
  <pre><code>override fun onRefresh() {
      viewModel.fetchLists(organizationId, forceRefresh = true)
  }
  </code></pre>
  
  <p>It will set the value of <code>organizationId</code> and trigger the Transformations that will then call network.</p>
  
  <p>But, I have a scenario where I clear the data from my RecyclerView's adapter. If after that, the user click a button, I would like to trigger the observer again so that I re-populate the adapter with the data that the getListsObservable has already fetched. I don't want to call forceRefresh on this one cause i'm sure I already have the data and I would just like to trigger the observer again so that my UI is updated with the existing data. Since <code>getListParams.value</code> is not null at that point, then nothing happens when I call <code>fetchLists(organizationId)</code> later on.</p>
  
  <p>Any idea of how I could achieve that with my current setup?</p>