0
votes

I'm using Android Room to load data. my query is this:

@Query("SELECT * FROM TrackedItem where isArchived = 0 ORDER BY creationDate DESC")
Flowable<List<TrackedItem>> getAll();

When calling getAll() I get all the items at the first time. Then, I'm updating all the items using a network request. What happens is that if I have 100 items, the getAll() will emit 100 times the entire list, which will update the RecyclerView 100 times.

Best practice for getting a single item that was changed and calling notifyItemChanged?

Thanks.

1
"I'm updating all the items using a network request" -- how are you doing this? One DAO call? 100 DAO calls? Something else?CommonsWare
changed it now to One DAO callShahar
And... did that clear up the problem? I haven't tested this scenario, and so I would hope that a single DAO call would result in a single update through the Flowable, but there's a reason Room is in alpha... :-)CommonsWare
Yep, that seems to solve the issue. Wiil update my answer soon.Shahar

1 Answers

0
votes

Answering my own question, if someone gets the same issue. Instead of saving each item after an update, I save all of them once calling @Insert with (TrackedItem... items). which will only emits one update.