i'm looking for a way to sync items stored in a database among users
so anyone of those users changes anything from his phone , the change will be reflected in the database and SYNC with all users related to him in real time
what's the best way to achieve the real time sync ? push notification ? is Urban airship what i'm looking for ?
Syncing data well is often specific to your application and your data. It's beyond the scope of an SO question but here's some thoughts if you implement your own ...
Some of the interesting design points are:
Reliably getting a delta
Dealing with conflicts
How real time is real time?
For reliably getting a delta, be careful about relying on date time for distributed machines. This post discussed some of those challenges and some alternatives.
Can I Rely on the iOS Device Clock Being Correct?
Merging new entities is easy but if multiple folks are editing the same entity, you need to decide how to merge. For conflicts, you can in order of preference (1) auto merge - come up with an algorithm that automatically merges the content without user intervention and ideally with no data loss (2) rely on the user to merge with an interface and (3) a form of auto-merge: last write wins. There's also variations where you interleave the revisions - it's a form of last write wins but the revisions are maintained . You can also auto merge at a field level of an entity if that's appropriate. My post to the question above covers interleaving but it depends on what your data is.
How real is real time? When syncing occasionally connected devices, the devices will getting farther and farther out of date and it takes time to catch up. Consider batching sets of changes in the communication pattern to optimize but it will still not be real time. Embrace that in the design - does the user see data animate into there current views as data is synchronized?
Architecturally, you'll likely want to expose your data in the cloud through REST services or SOAP web services since it's cross platform. For multiple devices platforms, you'll likely end up porting the sync algorithm. The best you could hope for is using something like Sqlite so you can share your devices database schema code and sql statements.
I would start with Dan Grover's presentation, "Cross-Platform Data Synchronization": http://iphone2009.crowdvine.com/talk/presentation_file/5104/Grover_Syncing.pdf
Related
I want to do "bus plan app". I have a question to you:
What way will be better to code plan?
in array, in data base, other way?
I don't want come to death end and go back to start point again.
I was thinking about array:
String bus_stop [one element - bus nr.] [arrive time] [departure time].
Where arrive time is mostly the same what departure time, and sometimes arrive time have 8 elements and other time have 38 (the same departure time). I think plan for next year is going to change, so important for me is to easy new plan update.
I was never before use database, but it's seem easy way to store and show data to user.
So please help.
I would defiantly use a database, using alternative approaches such as storing data in RAM or XML files can be quite RAM intensive and could slow down your app. as #SMR said, using a database would give you much greater flexibility and integration with other services (API's perhaps?)
As you stated you have never covered databases before I'll share a link to a tutorial on how to get started with SQLite on Android, Its the simplest way to integrate a database (and maintainable persistent storage) from within your android application. Link: http://www.tutorialspoint.com/android/android_sqlite_database.htm
So basically I have made a few small apps in the past, but this is my first 'proper' app.
One of the main features of the app, and the bit that I am struggling with is that I need to be able to populate a ListView with all of the other users logged into the app, however I only want to display users that are within a set distance, for example 10 meters.
I tried using Bluetooth to achieve this, however that didn't work. I would now like to use location services to do this.
My idea is to have to app send the location of the device to an external server every few minutes and then all other devices can run a function that compare their location to others found on this server.
Does anybody know how I could go about achieving this, or know of any tutorials that cover a simpler topic. Thank you
Disclaimer: I'm not an android developer, but this seems like a design issue not a implementation issue so hopefully my comments below might be of some use...
I don't think there's an API that you can just set to "true" to get this functionality, so I think you're going to have to custom craft all the moving parts (and there are a couple). I would think the general process would be something like:
On the client:
User on client logs in to server with some sort of identity (i.e. "user#gmail.com")
Every X minutes the client app gets the current location (i.e. "100N 90E") and sends it up to a server
Every X minutes the client polls the server to see who is within 10 miles (i.e."joe#gmail.com", "mary#gmail.com")
On the server:
Needs some sort of authentication endpoints for getting a user's identity
Needs an endpoint for users to register their location ("user#gmail.com is at 100N 90E")
Needs a service to find out how far each user is from each other
Needs an endpoint to return the users within X miles (list generated from #3)
Each one of these steps shouldn't be difficult on their own and you can actually get pretty nuts with the distribution algorithm on server step #3 if you wanted to.
Some questions you can ask yourself are:
"How do I set up a server to listen for HTTP requests?" - Take a look into Node.JS for a simple solution
"How do I get a user's location in android?" - Easy google search finds plenty of documentation
"How do I write a service to continuously perform actions?" - Node.JS would again help with this
"Where will I store user's locations and their distances from each other?" - You can look into a NoSQL option like CouchBase or MongoDb. Or you could use MySQL for a more structured database.
Hope this helps...
The situation: I have many real life locations with specific information associated with them, and updated frequently. I am unsure of how to store this information for use in an android application.
My original thought was storing the data on some server/cloud source/database, reading from the server from each Activity in the app to make sure the info is up to date, and update the server with any changes that may or may not have been made.
For example: there are 200 people inside the library, one person leaves.
So we would read the number of people from the server, display this on the app, person leaves, subtract one, send the new number back to the server.
Would this be an incorrect approach? I'm fairly new to Android in general, and I really have no experience on how to approach this type of situation, what services to use, etc.
I would look into using Parse, its a pretty sweet way to power the backend, and their website is very detailed in explaining how to use it.
I got an application that displays some items loaded from a webservice (e.g. Fruits). These items rarely change. You can also show availability of those items (e.g. for apples, 10kg is available at store A today, 20kg tomorrow, ...)
The user can bookmark some of those items on his phone. I need the user to be able to bookmark some of these items and to have his bookmarks synchronized between devices (I bookmark apples on my phone, I expect to see apples bookmarked in my tablet next time I open the app there).
More or less, I got around 40 items, no more. And each availability data would total to around 200 entries.
Which technique would you use to implement that?
My idea so far:
I build a sqlite database (with contentprovider) of fruits and availabilities
I synchronize this DB every 2/3 days (that is enough, no need to do it more often)
I use a BackupAgent to synchronize the whole DB file
Do you think a database is overkill? The application is expected to always be ran with network connectivity (else we don't allow it).
My other option would have been:
Load items and availability on application start
bookmarks are kept within SharedPreferences
I use a BackupAgent to synchronize only SharedPreferences
This seems less complicated, and more efficient on the sync part. However, I feel that is not really a clean way to do it and less future-proof.
Android's backup API is only useful to initialize a new device based on the backups created by another device. See the backup API docs. It is not the right infrastructure to keep 2 devices in sync.
I suggest you take a look at the Cloud Save features of the Google Play Game Services. It allows you to sync data on two devices. It is typically used by games but can also be used in other scenario's (like yours).
I'm making a client/server game app for android. Currently I managed to get the app working using two locally known IPs. My issue now is how do I go about making my app pair client/servers randomly.
I was thinking that initially every person starts as a client and they connect to a master server. The master server then pairs them together and specifies who will be the server and who will be the client between the two. If this is the best way to do it, how do I go about making the master server program? What kind of server do I set it up on? I'm in the dark about how to go with this.
actually i did not answer right away thinking i would waste the night in needless fear but let us - if you don't mind - bump the issue up the hill - given just now i am going clickety-click looking for places to put up my first app - i found 2-3
let us examine the chance to do conceptual work on what is called stochastic List
given a large dataset = available apps
and another large dataset = people looking for apps
how would we code a fair presentation algorithm as some numbers like 100,000 are not out of scope but we get the same 10-20 apps on many keyclicks & not get much done - thus:
class Customer{}
class Application{}
Map <BigInteger,Customer>
Map <BigInteger,Application>
then we look into SecureRandom to pull from the application base ....
lot of work to be done but major point is to use SecureRandom rather than Math.random for several reasons ..