android - CursorLoader not refreshing on data change -


i'm having bit of problem android's cursorloader. i'm using cursorloader load data own contentprovider. loads data , keeps on orientation changes not update on data change. way using cursorloader comes in compatibility library.

i think have done documentation , several tutorials tell me do, still not working. have checked several posts on site nothig seems fix it.

here's create loader:

@override public loader oncreateloader(int id, bundle args) {     switch (id) {                     case todo_evidences_loader_id: {             return new cursorloader(this, buildertodocontentprovider.todo_evidences_content_uri, null, null, new string[]{token_id}, null);         }     }     return null; } 

this method call on query method on contentprovider:

private cursor gettodoevidences(string selection){     string evidencequery = "select " + buildertodocontract.evidence.table_name + "." + buildertodocontract.evidence._id + ", " +             buildertodocontract.evidence.table_name + "." + buildertodocontract.evidence._path + ", " + buildertodocontract.evidence.table_name + "." + buildertodocontract.evidence._timestamp + ", " +             buildertodocontract.evidence.table_name + "." + buildertodocontract.evidence._type +             " " + buildertodocontract.evidence.table_name + " " + selection;     cursor result = database.rawquery(evidencequery, null);     result.setnotificationuri(getcontext().getcontentresolver(), todo_evidences_content_uri);     return database.rawquery(evidencequery, null); } 

this method call on delete method of contentprovider:

private int deleteevidence(string[] selection) {     int result = database.delete(buildertodocontract.evidence.table_name, buildertodocontract.evidence._path + " = ?" , selection);     getcontext().getcontentresolver().notifychange(todo_evidences_content_uri, null);     return result; } 

as can see creating cursorloader, calling setnotificationuri() on query , calling notifychange() on delete method passing same uri, onloadfinished() not getting triggered on data change. , not closing cursor anywhere.

as workaround i'm restarting loader manually beats purpose of using cursorloader loadermanager.

i'm not using cursoradapter, putting data in onloadfinished() inside evidence object, inserting object in list wich data source of custom adapter tied gridview. i'm doing because need add other data evidence object not present in cursor.

i hope can solve this. in advance.

cursor result = database.rawquery(evidencequery, null); result.setnotificationuri(getcontext().getcontentresolver(), todo_evidences_content_uri); return database.rawquery(evidencequery, null); 

you're not returning cursor called setnotificationuri on. you're returning second rawquery cursor. want is:

cursor result = database.rawquery(evidencequery, null); result.setnotificationuri(getcontext().getcontentresolver(), todo_evidences_content_uri); return result; 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -