That is what I have in my app
Everything works fine as expected, but one thing I can't figure out why it happens.
When I go to Fragment #2 to Insert or Update data to Room Database then back to Fragment #1 with (top or bottom) back button, fragment #1 doesn't reload and data doesn't change (update) until I reload data.
In other case when I Insert or Update data at the same fragment the list changes immediately.
Do I have to make insert and update operations at the same fragment?
Can't I do it at other fragments and when I go back to the list fragment I find that data is been updated?
Keep in mind that it was work like I hope but at some point i really don't know it doesn't any more !!
After searching, the problem was that I was create instance from repository which contain ROOM database DAO, So all LIVEDATA connections to the database was removed
The solution was to use singleton pattern, which mean to use only one repository instance and one room database instance during the full lifecycle of the activity which contain my fragments.
You can do this many ways, I recommend you to use Dependences Injection Tool I used was HILT DAGGER here here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With