title: Extract SQLBrite logic to external class in Android
body: <p>In my chat app I use SQLBrite wrapper to update chat from local database. Currently my activity holds both UI and SQLBrite. Now I want to extract SQLBrite logic to external class. So while my activity is living I need my extracted SQLBrite also be alive.
  Currently I have problem with subscriber. I also extracted it to external class, and its emitting query all the time, event though everything is same as it was while it was in activity, and it was working.</p>
  
  <p>this is old code, where everything was in same activity:
  How I can do this?</p>
  
  <pre><code>SqlBrite sqlBrite;
  sqlBrite = SqlBrite.create(DatabaseManager.DatabaseHelper);
  private final CompositeSubscription subscriptions = new CompositeSubscription();
  
  private void saveMessage(Message message) {
  
          ContentValues values = new ContentValues();
          values.put(DatabaseContract.MessageEntry.COLUMN_NAME_MESSAGE_ID, message.getId());
          values.put(DatabaseContract.MessageEntry.COLUMN_NAME_SERIAL_NUMBER, message.getSerialNumber());
          values.put(DatabaseContract.MessageEntry.COLUMN_NAME_TEXT, message.getText());
  
          sqlBrite.insert(DatabaseContract.MessageEntry.TABLE_NAME, values, SQLiteDatabase.CONFLICT_IGNORE);
      }
  
      private void subscribeToDbChanges() {
          String NEW_MSG_QUERY = "SELECT * FROM "
                  + DatabaseContract.MessageEntry.TABLE_NAME
                  + " WHERE "
                  + DatabaseContract.MessageEntry.COLUMN_NAME_CREATED_AT_MILLS
                  + " &gt;= ? ORDER BY "
                  + DatabaseContract.MessageEntry.COLUMN_NAME_CREATED_AT_MILLS
                  + " DESC";
  
          String grpId = String.valueOf(groupId);
          String msgDate = String.valueOf(dividerMsgDate);
  
          Observable&lt;Query&gt; freshMessages = sqlBrite.createQuery(DatabaseContract.MessageEntry.TABLE_NAME, NEW_MSG_QUERY, grpId, msgDate);
          subscriptions.add(
                  freshMessages.subscribe(query -&gt; parseQueryData(query)));
      }
  
      private void parseQueryData(Query query) {
          Log.d(TAG, "subscriber called");
          List&lt;Message&gt; messages = new ArrayList&lt;&gt;();
          Cursor c = query.run();
          try {
              while (c.moveToNext()) {
                  Message message = new Message();
                  message.setLocalId(c.getInt(c.getColumnIndexOrThrow(DatabaseContract.MessageEntry._ID)));
                  message.setId(c.getInt(c.getColumnIndexOrThrow(DatabaseContract.MessageEntry.COLUMN_NAME_MESSAGE_ID)));
  
                  messages.add(message);
              }
          } finally {
              c.close();
          }
  
          updateChatList(messages, "new");
      }
  </code></pre>