I have an Android application with a SQLite database from which I want to send some data to a webservice to store it in a database there.
How would I go about doing this? Is there a smart way of doing it?
I've thought about just extracting the data from the SQLite database and create an XML file to hold and then send the XML file to the webservice, but is there a easier/better way of doing this?
JSON is generally seen as a more efficient data format for transferring to and from mobile devices. Check out this post about how to do it. You will, of course, need a web service that can accept and interpret JSON objects.
Related
Implementing and managing remote or cloud databases in Android Applications is new to me. I am currently making an app that would take in thousands of "entries" to a form, think of it as an attendance app. Right now I've decided to use JSON as my database type and Parse as my BaaS. I need some tips on my decision.
I don't actually see JSON suitable for this because it is a "text" file that can easily be modified or if I somehow accidentally append an extra bracket it would render the whole database corrupt whereas SQL use queries like INSERT which I think is more secure. I just picked JSON because it works well with Parse. Do you think this is a good idea?
Another is what if the JSON file will accumulate tens of thousands of entries, how do you manage this huge database? Do you split it into several files (eg. every 1k entries make another JSON file) or is it enough to just dump all the data in that one JSON database file?
When using BaaS do you just sync the data in that server or do you also make backups of some sort (I don't really know how to put this)?
Thanks in advance!
JSON is not a database, but a data interchange format. You can have a database that uses JSON for communication, for internal representation, etc. but that does not make JSON a database in itself.
Parse itself manages the organization of the data. You communicate using JSON but don't have to care about how it's stored, updated, etc. internally.
So in your app, you should use SQLite for storing such amounts of information, or, depending on the app, just send it to the Parse server and execute the queries against it. You can see how it's done in the Parse Android documentation.
I am building an Android app that that involves taking pictures and adding text to it. In other apps I have built I have been storing the data locally as JSON data. I read that you should always save locally(JSON) at every step because you can never be sure when an activity will be stop.
In the app I am currently building I want to upload the data to a SQL database. For example want to take a picture, save it locally and edit it(while saving at every edit), and then upload it to server. Then I would want to display a list that accesses the database to display finished photos.
Can I continue to save things with JSON and then only upload certain things to the database or should I skip JSON and just go directly to database?
Is there any built in methods for sending JSON data to a SQL database? Just trying to figure out the best way to go about this. Any advice would be appreciated.
I would not store the data as JSON because you might need later to query the data or filter it which will be cumbersome to do it with JSON.
What I suggest that you store your data in sqlite (the text only) and then when you are about to send to the server you can serialize it as JSON.
There is no special method to send JSON data, it is just normal plain text over HTTP.
As general rule, data storage should be in a database and then you can use JSON (or XML) to exchange the data (e.g. sync it with the server)
Also, if you are sending large amount of data, consider compressing it before sending to the server
Ok i need my app to retrieve data from a DB and display it in my app, i know this can be done using XML/JSON parsing but the data is to be updated almost daily so updating XML file wont be a possibility. The server uses SQL DB, so is there any other way other than Parsing data from it? I have heard about web service getting data n returning it to the app but in my case will it work? Will ibe able to retrieve specific data i need from the server?
Thank you
Yes. You need to create one web service and deploy it on your server which query the database and return the response in JSON/XML format and then parse that response and update your app's data. That's the straight simple way.
As you said you need to do this daily, you can think of creating a Service for the task and might be you can use AlarmManager too.
Yes you can refer this link
Android (Java) Simple Send and recieve with Server - Fast Setup Challenge
Sending and receiving data from a web service using android
simple client server communication in android
I have an android app which populates a SQLite database with numerous latitudes and longitudes. I then need that data to be stored in an external SQL Server db. The problem I'm having is sending that file to a web service. I cannot find any examples on how the class should look that takes in the db file and stores it in a separate SQL Server db. Is this even the way I should be approaching my problem?
A better approach would be to send the actual lat/long data to db via a web service rather than sending the entire db file itself.
Doing it in this way would accomplish several things:
It should be much simpler to implement
You would not need to support SQLite on the server side, just the client
The data "set up" would be immediately available for querying - rather than needing to be extracted from the SQLite db file before it can be used
EDIT: How frequently and how much you upload is entirely up to you. You can make it user-activated or on some time interval and upload the latest data in bulk fashion or one-at-a-time until you're up to date. In either case you would track which data needs to be uploaded with a timestamp.
One simple method for transfering "in bulk" would be to pull the data that you need to save from you SQLite db and put it into a JSON or XML object which would be interpreted on the server as a collection of lat/long data. This would put the whole upload into a single web service call rather than having to loop through your "newest" records and calling a web service for each item.
Rather than sending a database to server you should have a mechanism that can export only data and send it to the database.
You can export the data into the CSV file or any other format and then you can send it to the sever so that server can easily read that CSV and insert that data into the database.
Also you can read your SQLite database and then you can make a structured data like XML, JSON.
then you can connect to the webservice and then send thay structured file to the server.
CSV is the best option if you have much data and you want to send it to the server.
I want to be able to store multiple List<NameValuePairs> for when multiple users enter information into my Android application using the same device. Later on, the user should then be able to send their data to the server at a click of a button. But this should only be for later upload for example when there is wifi/network connectivity.
What is the best way to go about storing these List<NameValuePairs>?
Well, your best bet is to store the data in Android's SQLite database:
http://developer.android.com/guide/topics/data/data-storage.html#db
As an alternative you can just serialize your objects to a file, but that might be too much of a hussle if the data is big.
Then you can have a service that runs in the background and sends data from the local db to the server when possible.
Here are your storage options:
http://developer.android.com/guide/topics/data/data-storage.html
I would imagine that depending on the kind of data and size, SharedPreferences or SqlLite could be useful for you. You can back DB with a ContentResolver and implement sync (SyncService) to upload to server. In this case, the Android OS will intelligently sync your data on the cloud when network is reachable.
Decided to save everything as a long string of name value pairs seperated by ampersands for easy upload to database when sending to php server.