I am working on a football scores application. How am I supposed to manage the live scores?
We have our own api, which is getting the data from a paid api. I know one method is to constantly hit the api after, let's say every 5 seconds, but is that the correct method? Or is there any other way? Thank you in advance.
There are several options for this type of functionality.
The first is to query the server every X seconds for fresh data (like you described)
The method I like better is using web sockets or other form of bi directional communication with the server that push the client the changes every time fresh data arrives from the 3rd party API or on some other logic you decide.
you have to use the Realtime database for the live score app. Websocket can send the data constantly and you don't need to call API every 5 seconds. Follow This Link to know about the Realtime Database. When there is any update in your database then the app will auto-refresh the data and show you the current score in your app.
Constantly hitting the API is not a good practice, this can hang your mobile.
Related
I have an SQLite database on Android and a MySQL database on a server. I want to synchronize these databases when a user edits data on their phone or edits data on a website.
I know how to update the MySQL database on the server when a user makes changes on their phone but I don't know how to update the Android database when a user makes changes on the website.
I have read into push notification and believe this to be a good path to follow but I have a few questions about it:
When a user updates data through a website it will send a push notification to that user's phone saying changes have been made. Can this push notification trigger to update the Android's database with the new changes made on the Server database?
What if a user turns off push notifications? Will I still be able to trigger for their Android database to be updated?
I have also read up on SQLite and MySQL database synchronization and found this post SQLite and MySQL sync but did not find the post helpful for my situation.
Are push notifications a good way to go or should I be using a different approach?
In a nutshell - I want a way for the Android device to detect changes on the MySQL database and update its SQLite database without the user initiating the synchronization.
I'm afraid I've not used push notifications. But a solution might be: You could create an early method call to an Asynchronous polling event from the launcher onCreate() that looks up the server to see if any changes have been registered (though an API of some sort) in the MySQL, and then update the SQLite that way? Since it's the first thing that happens on launch, technically the user isn't initiating it. Granted this won't update during use of the app, unless you repeat poll at regular intervals?
Token based pagination approach.
Assumptions: or calls you need to take
One of the databases will the source of truth, in case of differences in the two, which data is true, and which will be overwritten? - assuming remote database is source of truth
What's the frequency of data changes? - assuming its not realtime critical
How much stale data are we OK with dealing on the app. - assuming we're OK with a few minutes of difference
How to ensure data is consistent
Find a method to associate a token, which can be used to identify till which record is the data in sync. This is important no matter how assured you are of web requests, they will fail. So the best method is to send the last token that have stored, and the web endpoint will return data from that token to the latest value.
If the volume of data is too much here, sending chunks > sending all of it. Chunks work the same way, based on tokens.
These tokens can be simple PK auto increment column as well.
How to deal with time difference, stale data
If your application demands some data to be near realtime, better to categorize data based on a fiew screens, and whenever the user comes to the said screen, send a request in background to fetch related data columns only. Will ensure the data stays in sync w.r.t to the important columns. This is a classic push/pull approach. Can also be done on the splash screen itself.
as a rule of thumb, if you need something urgent, pull.
if it can wait, wait for a push.
Push notifications are OK as far as:
they should be silent.
there'a a limit on the number of push notifications that you can send
have costs associated
what's the fail - check mechanism? What if the requests fail?
Currently am developing an android application in which i wish to intregrate the webservices and save the received datas in my sqlite database.Further if there is any changes in my remmote sql i wish to update the same thing in my sqlite too.How can i acheive this..is there any way to acheive this.I just stuck in this thing for more than 2 days.
You have many options to perform the task:
You can ping the server for updates, for example if you upon starting call some API method getItems and store the items on local database, you can after certain interval call getItems again and replace the old items with the new ones
You can use a service like GCM (Google Cloud Messaging) to archieve this so your server sends the updated items straight to your phone, but this really depends on the application you're using it on
We are developing an application called marketwatch.where we have to show prices of basic commodities,what we have to do is create a db of commodities and their prices and display them in our app whenever we change the value in db it should be updated in our android app.
If i understand you correctly, you want your applications database to be synchronized with your actual database.
You can do this by two ways:
Pulling: which means that every time you open the application or every period of time, maybe couple of hours or something, you request from the server the updates that happened in your database, if any
Pushing: which means that when your server has an update, it should notify the mobile app by sending a push notification to tell the client that there is an update to be fetched.
You can combine both, for example low priority updates should be retrieved by pulling, but high priority ones should be pushed to the client.
Have a look at the official training resources for Sync Adapters.
Or, if you don't have any constraints for the server part have a look at Firebase (from Google)
I have mobile app. Something like to do list or calendar. Teoretically user can have a few devices with that application on a defferent platforms and so on. I would like to create a automatic synchronization between them through a own server. What is the best practice: update all the information or only the changes? On the one hand usually there is no a lot of data when it's about a to do list but who knows?
The correct approach is not date/time as others suggest, as time can go out of sync. The right algorithm is to keep the checksum of the data entries during last synchronization. On next synchronization you compare current checksums with stored ones, then you know whether the entry has been changed on the server, on the client or both.
Our open-source Rethync SDK lets you implement the above approach quite easily and is available for Android (not for iOS at the moment).
I am doing something similar in my application. I have a last modified date field with each entity that I need to sync. Then periodically, I post this data to the server (actual data + date and time). Now the server can do one of two things. It will check the corresponding data on server side and compare the last modified date. If what the server is latest, it will return the latest data in response. If not, it will update its data and send a response indicating what client has is latest.
Of course you can do several optimization. That is, mark the data as "dirty" so you know whether to even send your data to server. If the phone does not have modified data, your sync is basically getting the latest data from server.
Basically server does the heavy lifting and does all the logic necessary to maintain the latest data on its end and send responses to client appropriately.
Good Luck
Best approach is use a time stamp to handle this.
Initial request to server with time stamp value 0.
Server will give the all the data first time with Time-stamp.
Store the Time stamp to sharedpreferences.
In All next request pass the time stamp back to the server
Server will send only those data which are add/update/ after that
given time stamp
That is it.
There is a new alternative to the syncing problem. It's called EnduroSync from Orando Labs. You can sync object data stores between devices on Android and iOS now, with others coming soon.
Full Disclosure: I work for Orando Labs.
The EnduroSync clients allow you to create object data stores on the local devices. The clients are fairly sophisticated - data is modeled as native objects for each client we support (iOS and Android now, more coming). The clients work offline and online. The data is saved to an sqlite database locally.
As you change objects in your model, the deltas are recorded on the device. At some point, you can 'sync' the object data store. Syncing uses a commit/push/pull process (like git), but this is invisible to you. The sync brings your local copy up to date with whatever is on the server, and sends up any changes you have made. Conflicts are resolved using a timestamp based merge, so newer data is not overwritten by older data.
EnduroSync is an online service, so there is no server setup on your end.
There is also a flexible permission system which lets you share the object data stores in a variety of ways. For instance, most applications will have one or more object data stores for each user, for preferences, notes, tags, etc. You can also share object data stores per app, per user type, and with wild cards, many other ways.
So basically you use our client SDK's to model your data on the device. Modeling is with simple objects in the native programming language of the device. If you sign up for the syncing service, you get the syncing also.
Here is another approach.
Issue :I need to have the appointments of doctors syned to client (mobile device) from the server. Now the appointments can drop off or the data could possibly change on the server. Having the client to know what change and sending a request back to server could be an expensive service.
Possible approach : Have the server do the heavy lifting. Keep a table which stores values of time stamp and if a change happened with regard to an appointment - cancellation / reschedule etc. The client would then look at this table to see if anything changed. In reality we don't need to sync anything but only the delta which server can provide to the client based on what it has and what is at Client. There is one aspect which needs to be taken care of is updation of info from client to server and traditional conflict management can be done where client can update the server when a data connectivity between client and server exists.
Essentially the approach is to have only the deltas synced by maintaining a checksum or data change log to PUSH changes to the client.
For example my application contains some quiz and I want to know the results from each user who installed the app. Is there any way to collect these stats?
Yes.
Use for example the Parse Library. https://parse.com/docs/android_guide. It's very easy to set up.
When you have set it up and read their guide, you'll be able to save data very easily. I had mine up in about five, ten minutes and I can now save complex data.
The upside of using a cloud based solution (Parse is cloud based) is of course that you won't need your own backend (server and database). You won't have to code your backend script/servlet either.