Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

sqlite - Room RXJava load DB and only react to changes after

I've got a simple implementation of RXJava where when the app is loaded, the entire database is loaded:

Disposable ds = viewModel.geAllUsers()
   .subscribeOn(Schedulers.computation()) 
   .observeOn(AndroidSchedulers.mainThread()) 
   .subscribe(modelClasses ->
   {
    Toast.makeText(this, "RoomWithRx: " + modelClasses.size(), Toast.LENGTH_LONG).show();
   }, e -> Toast.makeText(this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show()
);

The issue is when I add a user:

Disposable subscribe1 = viewModel.addData2(new User(4, "ok", "test"))
 .subscribe(
  newUserID-> {  }, 
  throwable -> { }
);

Since I subscriped to the user table, each change triggers the subscriber and the entire database is loaded again. How can define a way where once the database is loaded in the beginning, only the changed Users should be loaded? There is no noChange() method unfortunately.

question from:https://stackoverflow.com/questions/66053546/room-rxjava-load-db-and-only-react-to-changes-after

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...