I'm learning more about RxJava (I know more about retrofit, but the company I work for does not use that unfortunately for me), and I'm trying to create a simple project with the room library and the fake store api. And I've thought of this project for a day or two and cannot find a way to make sure the database operation is done before navigating.
As you can see the "login" fragment updates the user (if found) in the database and redirects to the "account" fragment, but the account "fragment" requires the token to be set already and this worries me, because I believe it would be possible for the navigation to go through before the database operation finishes in another thread, is there any way to maybe notify the UI about the finished operation? (I've read about "onComplete()", but you cannot navigate to a different fragment from a background thread)
Any tips / links / comments will be appreciated, thanks :)
You could use Completable() or Single() to ensure insertion is completed. If you want to do navigation in the background thread, you can use handler
and runOnUiThread
but using some observable data holder like LiveData and observing it from view is a better solution.