android - SqlBrite Queries on Worker Threads -


i'm still new rxandroid/rxjava i'm having little trouble wrapping mind around , if i'm doing correctly.

i using sqlbrite update recyclerview rows returned cursor. when db operation performed on table, observable below responsible re-querying data. want return cursorwrapper (checklistcursor), want make sure running select * query on worker thread. checklistrecycleradapter subscribes checklistcursor observable , responsible managing cursor.

the code below seems way able query.run() run on worker thread , subscription return on main thread.

i guess works, don't believe standard way this. offer better method using observeon twice?

compositesubscription.add(db.createquery(checklist.table, checklist.query_all)     .observeon(schedulers.newthread())     .map(query -> new checklistcursor(query.run()))     .observeon(androidschedulers.mainthread())     .subscribe(checklistlistrecycleradapter)); 

i replace first observeon call subscribeon(schedulers.io()), in order perform query operation in background thread. map operator still perform operation in background thread, , after that, can change observeon update adapter. think way this.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -