Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient way to store data if no internet connection to send to backend Android?

I am using kinvey as a backend to store some data. Everytime the user answers some questions on the phone(Android), the data is sent to kinvey immediately. But there can be a scenario where the user is not connected to the internet, so sending the data has failed. I would like to know if there is any standard way to storing the data that hasnt been send in an efficient manner? Also how often should I try to resend the data that has not been sent? I would typically just put it in a db, and try to send whatever is in that table every 30 minutes or so and clear the table if the send is successful? Would this be ideal? Also I see that Kinvey doesnt have a mechanism to handle this automatically(correct me if I'm wrong).

Thank you for any suggestions.

like image 699
LoveMeow Avatar asked Dec 25 '22 05:12

LoveMeow


2 Answers

Local database is a good place to store your data securely. The thing is that you are sending data after every 30 min, you have to change that scenario.

Below are the steps:

  1. Check Internet connectivity, if available than work online no need to store data locally

  2. If internet is not available than store it in local DB

  3. You are able to get Internet connection broadcast from system whether it is connected or not if you get connection at that time sync your data with the server (No need to check every 30 min) (System always broadcast when it get connection)

like image 168
J.D. Avatar answered Dec 28 '22 07:12

J.D.


You can took a look at Firebase, feature that you're looking for is described in Offline Capabilities. If migrating from Kinvey is not an option - then store your data inside a DB and use JobScheduler to sync it to the backend when the conditions are right.

like image 31
Egor Avatar answered Dec 28 '22 05:12

Egor