'Confusing set of options to sync local Room data with REST api
I am somewhat overwhelmed/confused by the number of options available to sync data with a web api and could use some help to understand the best option.
I have a room database and want to sync parts of it at various times. There is one main set of data I want to sync more regularly. The other components are less important. I want to be able to interactively sync if necessary, but for the most part just have it done in the background. I needs to be done when the network is available, which it frequently is not, but I want to make sure it happens.
I have been triggering a Volley call when an event happens in the app to update all the important records. The data syncs and updates the local Room records when it has. The issue is that when it fails due to network connectivity it just tries again when the event happens again, so it may never sync if that event only happens when the network is not connected.
I looked at Transfer data using sync adapters, but did not see many recent articles/tutorials on its usage and it seems pretty complex. I saw a youtube video on JobScheduler and that looked like a good option.
It would be good to queue up the changes and sync them when the network is available but it would also be good to initiate the sync interactively for support purposes so I could get feedback on why it's not syncing.
I know this is not a coding question and may rely on opinion, but I really don't know which way to go and could use some direction.
Solution 1:[1]
you should use Work Manager to schedule tasks, you can use constraints for the background work like internet availability and more.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Amer Dajah |
