Android data best practices - android

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

Related

search through web-service with json

In my android application im using web-service to get information about food the problem that if i write appl instead of apple,row,skin it dosent fill automatically and an error message will be shown,, what i did i stored 2000 name from web service in sqlite and search through them is it wrong to do this ? and how can i search with misspelling in web-service without the error message ?
The api url http://api.nal.usda.gov/ndb/search/?format=json&q=apple&sort=n&max=25&offset=0&api_key=DEMO_KEY
Salam Enas,
If the data do change frequently (like a movies list) then it's not ok to store it in the sqlite and it's better to be stored in the server database.
If the data does not change frequently, then it's ok to store them on the sqlite database although the app size will increase by 2 Mb which is a drawback.
You may also want to consider other APIs if you are not committed to use this one.
When storing data on the server, HTTP requests burden can be alleviated by caching data on the mobile.
good luck :)

How do you choose your database type based on the criteria (SQL, JSON, etc.) and how do you ensure its integrity?

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.

Storing a large amount of backend data in Android

I am developing a places of interest app which will display the list of places of interest in a location.
When user chooses one, it will display more information and address etc.
How do I store all this data? Currently I am using a text file to store all the data and subsequently when user chooses a place, it will parse the text file and retrieve the necessary data for display.
Any advice on what is a better way to do this? I looked at SharedPrefs, but it is more like storing "key-value" pair and in this case I need to store a large amount of data.
I want the info to be available even when the device is offline, thus I can't download from an online server upon request.
Any other way to do this?
You may store it to XML file using XML serializer, here is very good tutorial for learning that,
http://www.ibm.com/developerworks/library/x-android/
and it can be easily parsed using Java XPath Api. Have a look at this at parsing XML files
http://www.ibm.com/developerworks/library/x-javaxpathapi/
Use SQLite
It can store large data.
It is available offline.
All your problems will be sorted out.
Hre we have a wonderful tutorial for sq-lite
http://www.vogella.com/articles/AndroidSQLite/article.html
How about a relational database?
http://developer.android.com/training/basics/data-storage/databases.html
Take a look at Serialization. If you do not need database access, you could define a class what holds every information you need. Then, you can do the following:
when you need to save the datas, you serialize your object, dumping its content to a file, for example on the SD card
when you want to load the datas, you just load the above mentioned file, and get back everything from the dumped file
I am using this method in my app to cache some datas that would need internet access, so the user can still view it, and with proper implementation, this can work very nicely.
Use database, create table and insert all the data in it. When you need the data just fire the query, and you are done.
SQLite is fine for Android.
Depending on the type of data you want to store, you could use a SQLite Database (provided with Android) if it has a normal database structure. You could Serialize your data and save it in a raw or encrypted file, making you data implement Serializable.

Sending SQLite db to web service

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.

Send data from Android app to web service

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.

Categories

Resources