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
Post a Comment