title: Room Database Query from background Thread
body: <p>I have read that one of the ways to query data in room database is to use Livedata which can be used on the main thread as it is asynchronous.</p>
  
  <p>I would like to use LiveData instead of RxJava or AsyncTask.</p>
  
  <p>For this in my repository class I have function getSomeData() which returns LiveData> and I call this function in my viewModel constructor:</p>
  
  <pre><code>private var mObservableSomeData: LiveData&lt;List&lt;SomeData&gt;&gt;
  
  init {
      mObservableSomeData = repository.getSomeData()
  }
  
  fun getSomeData(): LiveData&lt;List&lt;SomeData&gt;&gt; {
      return mObservableSomeData
  }
  </code></pre>
  
  <p>However it crashes saying: </p>
  
  <blockquote>
    <p>Cannot access database on the main thread since it may potentially lock the UI for a long period of time.</p>
  </blockquote>
  
  <p>What should I do?</p>