title: How can I selectively observe Android Room database INSERT, DELETE, and UPDATE events?
body: <p>I have DAO designed this way.</p>
  
  <pre class="lang-java prettyprint-override"><code>@Dao
  interface FooDao {
  
      @Query("SELECT * FROM foo")
      LiveData&lt;List&lt;Foo&gt;&gt; stream();
  }
  </code></pre>
  
  <p>The above lets me receive <code>INSERT</code>, <code>UPDATE</code>, and <code>DELETE</code> events all at once, which I have no way of knowing whether the data is recently inserted, deleted, or being updated.</p>
  
  <h3>Goal</h3>
  
  <p>My goal is to be able to update the database rapidly and have RecyclerView reflect the changes without stuttering or completely freezing.</p>
  
  <h3>Current situation</h3>
  
  <p>I have a background service that's updating the database and using the above method, I'm using the <a href="https://developer.android.com/reference/android/support/v7/util/DiffUtil.html" rel="nofollow noreferrer">DiffUtil</a> class to calculate the difference and update the list accordingly on the front end. </p>
  
  <h3>Issue</h3>
  
  <p>Because updates are coming in so fast, the RecyclerView gets frozen up. I added background processing (DiffUtil calculation) using RxJava (since I have it in there anyway), which only reduced the stutter significantly though not completely.</p>
  
  <h3>Ideal goal</h3>
  
  <p>I need to figure out a way to update the list individually or if at all possible, skip receiving only <code>UPDATE</code> events from Room leaving out <code>INSERT</code> and <code>DELETE</code> events since these are done manually so should not be able to freeze the UI. </p>
  
  <p>That way, I can use EventBus to notify the adapter that a row has changed from the background service without triggering <code>UPDATE</code> events from Room, which would have otherwise caused the adapter to perform the DiffUtil calculation, therefore slowing the UI down.</p>
  
  <p>This means isolating database events for <code>INSERT</code>, <code>DELETE</code>, and <code>UPDATE</code> or selectively observing specific events only.</p>
  
  <p>Is there such a way with Room and if so, how can I achieve this?</p>