title: How to setup an application level livedata observer pattern
body: <p><strong>Background</strong></p>
  
  <p>I have multiple ways to get data from server, such as background polling and server push. These items may be contain same item.when data is ready, I insert these data into database with Android Room. when the insert item have exist in database, I will abort the item. I expect to get notify when these data insert success, so I use livedata in the Dao:</p>
  
  <pre><code>@Dao
  public interface WordDao {
  
  
      @Query("SELECT * from word_table where isNew = 0")
      LiveData&lt;List&lt;Word&gt;&gt; getAlphabetizedWords();
  
      @Insert
      void insert(List&lt;Word&gt; word);
  
      @Update
      void update(List&lt;Word&gt; words);
  
  }
  </code></pre>
  
  <p>In the <code>application</code> code:</p>
  
  <pre><code>@Override
  public void onCreate() {
      super.onCreate();
      wordRepository = WordRepository.getInstance(this);
      wordRepository.getAllWords().observeForever(new DatabaseObserver(this));
  }
  </code></pre>
  
  <p>In the <code>DatabaseObserver</code>, I receive data change notify. I will handle these data, then I will set one property of the class(set <code>isNew = 1</code>) to indicate that the item has been handled. At the same time, that handle keep the later insert will not notify old insert data.</p>
  
  <p><strong>My Question</strong></p>
  
  <ol>
  <li>Is this pattern using <code>observeForever()</code> will be worked as expect?</li>
  <li>When I write the demo code, I encounter that the <code>DatabaseObserver</code>'s <code>onChanged</code> method receive same item list. After I change my code like <a href="https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1" rel="nofollow noreferrer">this</a>, the problem is still there. How to resolve this problem?</li>
  </ol>