SQLiteDatabase or XML(saving)? - android

Thanks for making android a wonderful platform.
What is the best option for saving a well formatted document(a document with images) on a device?
I know this can be done by saving to a XML file or on a database, but which of these two is the most preferable.
Thanks in advance.
-Ernest

Usually using XML or SQL database are differents approches for differents needings. Typically a database solution is more efficent than XML.
But XML has a tree structure that is easier to map in a object oriented language. I'll suggest you to use XML for the following reason:
easier to load data from xml to an object into your program
Easier to modify your page structure (with sql without a ORM system maybe difficult)
you are saving a "well formatted document" with images which has a naturally XML representation
You are on a mobile device and i don't think you need something like concurrently access to the same XML file or things like that
SQL would require installing a database, XML are just a standalone format

Related

How to fill data into xml format?

I have a huge amount of data (200 pages) and i need to import it to sqlite database through XML(in android)
i want to parse xml data and save it to db in android...
i want these data available from the first installing the app...
i want to know what is the easiest way to import data into XML format...
because data is too much lengthy i need some help from you to solve it easier...
what is the easiest way to achieve to suitable xml format
is there any software to handle this problem or should done manually???
how to put data in xml format ?
use simpleframework.
It is a java xml serialization/deserialization library which is pretty easy to use.
I used it in my last android app and it works really well.

Load large amount of data to DB - Android

I'm building a new application to the Android platform and I need a suggestion.
I have a large amount of data that I want to import into a sqlite DB, something like 2000 rows.
My question is what is the best method to load the data into the DB?
Two ways I think of:
An xml file that holds all the data and then loads it with DocumentBuilder object.
A CSV file, and loads it with String Tokenizer. Found that post.
I want it to be with external file because When I release an update I will replace only the that file.
I want something that would be efficient as much as possible - all the data will load at the first startup of the application and I need it to be fast.
Any suggestion would be great.
Thanks.
Use InsertHelper to do a bulk insert.
Take a look on this other question
Instead of XML or CSV files, you can directly use an external sqlite DB you prepared in your computer. This technique is explained here: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
It really does not matter - you can achieve good perfomance with both approaches. With XML you can use some databinding, making programming easier (marginally). You may also consider JSON as transport format.
When parsing, keep in mind that building complete object tree in memory ( like XML DOM parser) consumes a lot of memory and results in a lot of allocations - pull parsing model like XPP / GSON is preferable.

How to load an SQL query from an XML file on Android?

For the Android app that I'm working on I have to do some lengthly sqlite queries, and it was making my code hard to follow. Is there any way I can put the queries into an XML file and then load them from there?
I'm attempting to do something similar to this.
You could create an XML file like the one you linked to under the res/xml/ directory, or use the res/raw/ directory and store it in some other format of your choosing. Then read the resource in as you normally would with Android, parse it if necessary, and interact with your database directly by using SQLiteDatabase.execSQL.
For specifics, it really depends on your needs and application architecture.

What type of storage for some text in android?

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.

How to storing data in my own application

I would like to build some simple application - for example Todo list - and I am thinking about the problem and its solving - how can I to store data in my own application on Android platform?
I should to use some text file, xml file or some database? What will be better for beginner on this field?
You'll have a VERY hard time getting anywhere with Android if you don't read through their website/dev resources. I would highly recommend visiting their site.
As far as data storage is concerned, that varies based on your need. Explained here
My suggestion is to use SQLite that comes with Android. http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
In my opinion, a SQLite database seems most appropriate for this kind of application. There is lots of support for using the SQLite database in conjuction with ListViews (which I imagine you'd want to use in your to-do list app).
In case you haven't already checked it out, see the page on the developer site:
http://developer.android.com/guide/topics/data/data-storage.html#db
Theres a few ways you can store data. I've created a few applications thats store data using shared preferences
They're quite handy for storing strings, ints, bool values etc. However if you have a large scaled application, that requires better database management, I would look into sqlLite.
Android has supported classes and functions to help access/store the information.
Theres a good tutorial on the android site called notepad that takes you through how to use sqlite.
That should get you started :)
Look at this Thread klick
Edit: its cool for less data, if you want to store and browse lots of data, you should use as SQLite Database
Using a file, database or xml based depends entirely on what kind of application you are building. For eg: If you parse an XML feed and store the results back in an XML file - it totally defeats the storage purpose!
Databases are used to store structured and related content like - news feed results, email client data, etc.
Files are more used for storing raw / binary content like storing images, attachments, etc.
BTW, if you are a beginner - you should try all of them! :)
Hope this helps!

Categories

Resources