I am using the sqlitecursorloader lib from commonsware. I receive GCM messages in an Intentservice and would like to insert an entry into the sqlite database. It should update the listview if the app is open.
I tried using this in the activity where the loader is initialized:
public static void createDbEntry(String Title, String Message) {
ContentValues values=new ContentValues(2);
values.put(DatabaseHelper.TITLE, Title);
values.put(DatabaseHelper.MESSAGE, Message);
loader.insert("constants", DatabaseHelper.TITLE, values);
}
and this in the intentservice:
MainActivity.createDbEntry(title,message);
As far as I can tell this works most of the time but if the loader is recycled I get a nullpointer.
Should I initialize a new loader in the intentservice?
Please help, I am new to android development.