Ormlite Notify Loaders to update

947 views
Skip to first unread message

Nicholas Campion

unread,
Dec 20, 2012, 2:44:40 PM12/20/12
to ormlite...@googlegroups.com
I looking at 'enhancing' the Loader code put forward by jc on this list and wanted to get feedback from anyone who might already be using it.


I've noticed that most of the CursorLoaders and example Ormlite Loaders seem to depend on side channel notifications of data being updated in the database. Per this code which jc shared with the list, the method registerContentObserver is called on Cursor. Im my limited testing, this does not seem to fire for my operations executed via a Dao. After some digging into the Android source of AbstractCursor and SQLiteCursor, it appears that this is because each cursor gets its own registered observer but separate actions against the database do not reuse the same Cursor and don't seem to trigger the previous Cursor's observers events. A similar conclusion was reached in this Stackoverflow question.

I'm exploring ways to fix this and, based on Commonware's Loaderex package, through about holding a List of weak references to Loaders created using the Dao as the hub. When a getXXXLoader method is called against the Dao, its added to the list. When a Dao method (create, update, delete) is used, the integer return value is checked to see if it is greater then 0. If it is, all loaders are nudged to reload their datasets. 

I'm throwing this out there to see if a) people have the existing Cursor method working by some other method or b) if this seems like a good way to solve the issue. The other way I have been tossing around is described in the stackoverflow question. Basically, we'd generate a unique URI for each Dao table and then piggyback on the Content Provider system to do notifications. The major difference is that, instead of having the Dao directly notify the Loader, the Dao would notify the system that the data at the generated Uri has changed and the loaders would be notified as a consequence. 

Any feedback?

Nick

Manuel Dugué

unread,
Jun 4, 2014, 8:17:04 AM6/4/14
to ormlite...@googlegroups.com
did you find any answers yet?

Nicholas Campion

unread,
Jun 4, 2014, 8:58:58 AM6/4/14
to ormlite...@googlegroups.com

We ended up moving away from cursors before I could solve this issue. Sorry.

--
You received this message because you are subscribed to a topic in the Google Groups "ORMLite Android Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ormlite-android/ethvAnobKpo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ormlite-andro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrei Verdes

unread,
Jan 27, 2015, 9:16:03 AM1/27/15
to ormlite...@googlegroups.com
Why did you moved away from cursors? What is your solution now?
Reply all
Reply to author
Forward
0 new messages