Need some help in using databases in Android.
I am trying to insert data into a db provided by MoEngage
from doWakefulWork()
inside WakefulIntentService
.
Here's my function to insert data into db :
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: ");
}
}
}
However, when I open the app and try to query the database, the cursor returns 0 count.
If I try to query right after adding values inside doWakefulWork()
only, the cursor shows the value in database.
Cursor cursor = MoEController.getAllMessages(App.context);
Am I missing somethings here? Any help would be appreciated. Thanks!