5

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.

LoveMeow
  • 3,858
  • 9
  • 44
  • 66

4 Answers4

4

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)

Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53
J.D.
  • 1,401
  • 1
  • 12
  • 21
  • I won't recommend using the system connectivity broadcast, since it will cease to work in Android N (http://www.r-bricks.com/2016/04/android-n-3-implicit-broadcast-removed.html), JobScheduler is a better alternative for tasks that depend on network connectivity. – Egor Jun 01 '16 at 13:12
2

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.

Egor
  • 39,695
  • 10
  • 113
  • 130
  • Migrating from firebase at this point would be a little too late, but I will look into it thank you! – LoveMeow Jun 01 '16 at 13:08
2

The other answers cover most of the use cases.

But if you don't want to use system broadcasts, another alternative would be for you to store the data on a database (SQLite, Firebase, etc), and try some sort of exponential backoff strategy to send your data to the server, using the AlarmManager for example. (Tutorial here).

You can try to check the internet connection from time to time, and send the data. If it fails for some reason (slow connection, connection drops, or no connection at all), try again later. Once you succeed, you can either remove the data from your data storage, or set up a flag like isSent = true.

Mauker
  • 11,237
  • 7
  • 58
  • 76
2

Kinvey is rolling out offline sync capabilities to all their SDK's, it's currently in Beta. If you use iOS or Javascript for mobile development, check out the "3.0 beta" SDK's. You mentioned you use Android, support for that platform will come soon as well.

In your case, you need a cache store, it will save the data locally and sync automatically if there is no network. You don't have to worry about when or how often to sync.

http://devcenter.kinvey.com/ios-v3.0/guides/datastore#CacheStore

Ivo Janssen
  • 476
  • 3
  • 9