Save data to local storage and send it to the server when it is online

I have a form to send data to a server when the device is online, but when the device is offline, I want to store the data on the local device and automatically send data to the server when the device is online.

Does anyone have an example or documentation on how to do this? I haven't started building the app yet, so I don't have any code to share.

+3


source to share


2 answers


you should check the connection, if the user was not connected to the internet, you should save the data to your local storage, then you should listen to Connectivity Status after that you can send the data using Background Service or other methods like Alarm Manager to check periodically connection status;



0


source


you can use the service for what i was working on the same problem. I made one sync service class that extends intent service. so you will need to store all data in a local db with one load status and pause in every call service class in that service class, you need to get all data based on the load state you have to load. and send data to the server via asynktast or whatever. and after a successful download, change the status again. When the network comes to resume, gets called and gets into the service class, and the process is in progress, you can use the notification builder for the display process.



0


source







All Articles