title: Inserting data into db from wakeful intent service in Android
body: <p>Need some help in using databases in Android.</p>
  
  <p>I am trying to insert data into a db provided by <code>MoEngage</code> from <code>doWakefulWork()</code> inside <code>WakefulIntentService</code>.</p>
  
  <p>Here's my function to insert data into db :</p>
  
  <pre><code>private void addToDb(Bundle extras) {
      String msgDetails = "my string";
      ContentValues values = new ContentValues();
      if (null != msgDetails) {
          values.put("msg", msgDetails);
      }
  
      Uri newRecord = App.context.getContentResolver().insert(MoEDataContract.MessageEntity.getContentUri(App.context),
              values);
      App.context.getContentResolver().notifyChange(newRecord, (ContentObserver) null);
  
      if (MoEHelperUtils.isDebugEnabled()) {
          if (null != newRecord) {
              Log.d(MoEHelper.TAG, "PushMessagingListener: added new record with entry: " + newRecord);
          } else {
              Log.d(MoEHelper.TAG, "PushMessagingListener: FAILED to add new record with entry: ");
          }
      }
  }
  </code></pre>
  
  <p>However, when I open the app and try to query the database, the cursor returns 0 count.</p>
  
  <p>If I try to query right after adding values inside <code>doWakefulWork()</code> only, the cursor shows the value in database. </p>
  
  <pre><code>Cursor cursor = MoEController.getAllMessages(App.context);
  </code></pre>
  
  <p>Am I missing somethings here? Any help would be appreciated. Thanks!</p>