title: LiveData in Background Threads or non-UI components
body: <p>Dears. I used to develop Android apps using MVP pattern and now I'm trying the MVVM with Architecture components like DataBind and LiveData.</p>
  
  <p>I wrote my Repository class that provides a LiveData:</p>
  
  <pre><code>LiveData&lt;MyEntity&gt; getById(long id);
  </code></pre>
  
  <p>For Activity/Fragments I observe the LiveData exposed by ViewModel (that uses my Repository) and everything works fine.</p>
  
  <p>The problem is I have to schedule an Alarm to display a Notification with a text related to MyEntity, so I created an Intent containing my MyEntityId as an Extra.</p>
  
  <p>When the AlarmManager calls my BroadcastReceiver, I need to use the Repository to get MyEntity. The point is how to "Observe" the LiveData inside a non-UI component.</p>
  
  <p>Also, I can start an IntentService (background thread) to avoid accessing the Repository in the Main Thread, and use something like "blockingNext" from RxJava, but I still could not figure a way to wait for LiveData.</p>
  
  <p>What is the correct way of doing this? Note that my Repository may not be implemented using Room, due to legacy issues.</p>
  
  <p>Thanks</p>
  
  <p>The only solution I figured so far was have methods like this in the Repository:</p>
  
  <pre><code>LiveData&lt;MyEntity&gt; getByIdLive(long id);
  MyEntity getById(long id);
  </code></pre>
  
  <p>But this does not look good for me.
  So I'd like to ask how is the correct way of implement this.</p>
  
  <p>Best Regards</p>