android - Updating a cursor object in a thread when onChange is called in the ContentObserver -
i have intentservice
tracks changes of database table of outgoing messages using contentobserver.
i watching when of rows hit specific state. when happens want finish intent service, or let service retry operations on row did not complete properly.
i can build contentobserver , know when data changes , onchange(boolean selfchange) called.
but how update ongoing loop in calling intentservice watching cursor? how use onchange call update/requerry cursor using in intentservice?
my contentobserver anonymous class , cannot assign new value cursor outgoingmessagecursor
eg:
cursor outgoingmessagecursor = getundeliveredmessagescursor(); contentobserver messageobserver = new contentobserver(null){ @override public void onchange(boolean selfchange) { super.onchange(selfchange,null); } @override public void onchange(boolean selfchange, uri uri) { super.onchange(selfchange, uri); } }; outgoingmessagecursor.registercontentobserver(messageobserver); while(outgoingmessagecursor.getcount() > 0){ //there still messages handle try { thread.sleep(2000); log.d(log_tag,"undelivered messages: " + outgoingmessagecursor.getcount()); } catch (interruptedexception e) { e.printstacktrace(); } } outgoingmessagecursor.unregistercontentobserver(messageobserver); outgoingmessagecursor.close();
how can escape while loop when messages have been handled?
Comments
Post a Comment