I am developing an Android application. This app deals with contact information (name, number, photo), which I need to store locally for later processing. This data also needs to be modified frequently.
What would be a good way to achieve this? I was thinking of "File input stream Internal file storage(achieved by serialized)" and SQLite, but am confused about both of them.
Can anyone tell me the difference between these two in terms of performance, speed, memory consumption etc.?
(Besides, what is SQLite3?)
(My personal opinion)
Database is slow compare to File but it help you in getting data in arranging formats and easily you can perform any aggregate function on it. I suggest you to use Database in your requirements. As you can store particular record in arranged format.
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
as your data is like contact information name, number, photo for any people so prefer SQlite it will be easy and effiecent to add update and delete
Consider the point native Contact also uses the SQlite for same type of data set
Related
I have read through the Android Storage Options and I have a question that I haven't been able to find the answer to:
Should I use SQLite to store my data or should I use a JSON object that is written to a file?
Requirements:
Store (up to) a few hundred instances of the same object. Each instance will be somewhat complex, storing reference to images, smaller objects, etc. The data will be stored locally, with the option of cloud backup. All the data will be loaded on startup and saved when manipulated by the user.
The reason I ask this is because I don't have a lot of data to store - for a SQLite database there will probably never be more than a few 100 rows, which makes me think SQL is overkill.
Also, exporting my data to a JSON file will allow me to easily import/export from different device platforms (I already do this on iOS).
Or, maybe there's a better option? If there was an NSCoding type library for Android I would probably use that.
Any opinions are helpful.
Thanks!
From the presented so far, storing in files will be more advantageous.
Considering that each "unit" is less than 16 attributes, a json file with short identifiers will likely generate a larger file representation than the SQL representation equivalent.
However, the local file manipulation will allow for easier interactions, as well as easier backing up/down.
Also, the File class is simple enough to generate less issues when compared to SQL.
Finally, given the choices, you are going to have to evaluate the operations used.
If you are going to compare the data, then SQL is likely to go faster, but if you are just inputting/outputting each data as a separate object, than files are going to be as fast as SQL.
Finally, please, particionate your objects, do not create just 1 file with all the info.
I have read through the Android Storage Options and I have a question
that I haven't been able to find the answer to:
Should I use SQLite to store my data or should I use a JSON object
that is written to a file?
You need to analyse your requirement again.
maybe there's a better option?
It depends upon your requirement.
if Your requirement is fixed to simply storing and retrieving then you can have a look on tinnyDB, which is basically using the SharedPreferences as storage mechanism. But if you need case base based selection/query of data then you should go with SQLite.
I am making a dictionary app and need to store and access my data from the app. My goal is to make a completely offline dictionary.
I have all the data needed in JSON format (the file is about 9 MB), so I can convert it into any other format or even into sqlite database.
I try to dig some guides, but it appears to me that Android apps use sqlite only for user data. But I know that there are plenty of other offline dictionaries.
How do they store words and translations internally in the app? And what is the best way to do that?
For the amount of data you need to store, SqlLite is the best option. Sqlite has a wide array of applications in Android apps; their scope is not limited to storing user data. The next best option would be to save the Json in a text file. You can then load the Json data in memory (when the app starts) and transform that to a dictionary structure with the JSON parsers.
Downside of JSON: You need to load your entire stored JSON in memory before parsing it. With 9MB, its not a good idea.
SQLite is the best option if you do not want your 'entire' dictionary in memory at all times and need values only on a look up basis. You also get the full functionality of basic SQL statements with SQLite. Also, there is a lot of SQLite help online; choosing tried and tested technology is always good.
Take a look at the developers website: http://developer.android.com/guide/topics/data/data-storage.html
I'm creating my first android app that will make use of SQlite. I have zero experience with databases, except for creating a mysql database to use with wordpress...
Edit: After doing some research about rest, I'm still confused about how rest, sqlite, and android dev fit together. My goal is to access a rest-based web service through a url and access certain datasets, then store them in my SQlite database. Then I want to access the contents of the database through my java program, and use them accordingly.
The datasets can be downloaded individually in CSV format, but because I will be using so many of them, I don't want to go through every line individually and store them in the database. I'm hoping there's a more efficient way to store these datasets in the database.
My main questions are:
How can I copy the XML contents of a webpage from a url into my sqlite database? Can I do this with my java program, through the sqlite database, or a java library?
Do I only need to copy the contents of the webpages from the url into the sqlite database one time? If so, what can I do if any information is changed in the datasets?
You first need a schema for your sqllite DB. That schema should map to the objects behind the web service. For e.g, you need a Person table in your DB if there is a Person entity on the web. It depends on what all you want to capture.
When you are done designing the schema, you should start writing the code that help you create & manage DB on android. This is done with the help of SQLiteOpenHelper class:
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
If you need to keep the DB synce'd with the data on the cloud (web services), you should implement sync. Android provides a very efficient sync framework.
Also, do watch this video from Android engineers explaining the best practices: http://www.youtube.com/watch?v=xHXn3Kg2IQE
Note, to actually fetch the data from the web service you would use UrlConnection API:
http://developer.android.com/reference/java/net/URLConnection.html
This sample probably captures most of it.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
In terms of reading CSV files, there are some good resources here:
Can you recommend a Java library for reading (and possibly writing) CSV files?
Once you have read each CSV line into an object, then you can turn around and persist it to the database. I'm the author of ORMLite so I'll talk about using it. I don't believe there is a hibernate port for Android.
There are a number of Android examples to help you to get up to speed with ORMLite. Also some good tutorials. If you want to write a number of rows at once then I'd recommend using the batch tasks ORMLite feature. For information, see the discussion about creating lists of objects on the mailing list.
I can answer your first question about " I'm not sure how to add them efficiently"?
yes, SQlite is very powerful and intelligent, you can add thousand of records in one transaction, just like traditional database, It significantly improve performance.
about second question, as my understanding, because CVS file is very simple, so you can download and analyze it by yourself.
I'm making a game to run on android. So I want to store player names and the winner, which I will also list up in a view. What is the best way to do this, use a database or write to a file (if so, what type, xml?). I have to be able to add data after every completed game, and the size won't be so large. What would be the best solution?
IMO, using a SQLite database would be the most straightforward. You don't have to worry about the xml parsing that goes along with an xml file. Additionally, the data your storing seems to have a natural relationship that would be conducive to a SQLite schema. For more information about how to use SQLite in Android, see the data storage documentation here.
SQLite is great if you have database concerns and want that sort of data lookup.
However, if you really want to do it Simply with XML then you can in Android.
I will be making a mobile application in Android. My application is like Google Map's Get Direction feature, but a lot more complex, so I need to store data about points in the map. So I'm worried that SQLite may not be able to handle these large amount of data(or considering the limited storage of the phone). I have no background in SQLite so please bear with me.
SQLite can handle large amount of data, the problem here is the device's limits. If you are going to store 3MB or more you should consider saving that data in an external server and access it via the Internet. In fact, when you are building an application that use large amount of data, usually the application don't use all data all the time, so you can save in cache (in a local database) the data that the app is currently using or is about to use.
I think the best way to find out is to write a simple app that simulates the types of transactions you'll be doing and see how it does.
You might also want to compare how SQLite does to an object database like db4o, which is very performant and used very often as an embedded database (and can easily handle gigs of data).