-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using getValue() on LiveData returns null with Room #44
Comments
don't return LiveData if you want the value sync. |
This reference might help you. |
I have added a observer in activity but still getting null in case of LiveData. and correct value when object is returned without livedata. |
I think for the first time it returns null and when data is changed then only it returns the changed value. |
if you want to receive sync data from the DB, just use a sync query. |
Ok then just call room on a background thread and declare your query to return the data sync. |
We would need to do a sync call to initialize the data and then observe the same LiveData for subsequent changes, just like my authentication scenario I posted on Statckoverflow. At startup I want to load the saved token, and then observe it as the token may be invalidated(by background sync task) or updated by the user when they log-out(logging-out doesn't delete the token as it may still be valid and can be re-used especially if the user is disconnected). |
I think that this is a completely valid use case. I want to sometimes just get the current values as they stand, and sometimes react to their changes. I'm not sure whether this change would have to be at Android.Arch.LiveData or whether it would be on Room, but calling LiveData.getValue() to return a synchronous value would be great. |
Room always returns Null value while using LiveData but returns proper value when we are not wrapping the value with live data. Kindly help us to resolve this. I tried inserting the new data but it is not reflecting as expected. |
I have a POJO set up for use with Room and retrofit
And have the following method in my Dao
However when using
the method returns null.
As a workaround I am omitting the LiveData when I want to retrieve the value once and want to update it (Using an observer leads to a loop).
Dao
Use
The text was updated successfully, but these errors were encountered: