Which is favourable, efficient and faster? storing information in xml format and retrieving it or storing information in a db on android?
and also, in terms of portability, xml could be stored as an asset...can the same be done with db? do db come in as default package in all phones.
application involves dealing with over 1000 records of data.
A SQLite DB will be faster when it entails large amounts of data - it will find what you want much faster.
For small amounts of data a KML file will have a much smaller overhead than the DB, but isnt very useful for dynamic data.
If the data needs to be updated or added to, you would have to store the file in a writable location if you want to continue using the xml file.
For around 1000+ entries I would be looking to use a SQLite DB - you could do one of two things here - precompile a DB for your application, then place the DB file into the asset folder, then on first run check if the DB file exists - if not move the file from the asset forlder to the DB folder (see note below).
Alternatively you could store the entries in a KML file in the asset folder, then on first run use a parser to write each entry from the kml file into a DB.
Getting files from the KML or a CSV file would take a while to process depending on the number of entries. I have an app which will get data from a csv file on the SDCard, and load it into a DB, as a test around 7,000 entries took about 35 seconds on a desire.
Also I think the raw and asset folder has a size limit of around 1mb.
Take a look at this link, it shows a very useful way of moving a large DB on first run of the application:
Database Populating Solution
You can't use assets/raw folders as writable resources. They're readonly.
So basically you have 2 options:
Store data to DB (SQLite)
Store data in preferences - in fact XML file stored somewhere/smth like
/data/data/[your package]/shared_prefs
My personal choice: if data size is more than 100 records - use DB, if less preferences.
My choice is
I use DB for structured data. When there is certain need in searching through data set by some fields or sorting by different fields. Use DB when there is additional logic is required.
I use "shared prefferences" files when there is only need in persistence of data. No additional logic, only key value pairs.
Related
I have a static table around 100 000 records. How should I use realm so that it can save my time? As I know I can put my static table (in case of sqlite) directly in assets and can access it's data.
Is there any way to put static data (rows), so that I can save my time to manually enter the data?
I already used realm's
realm.createAllFromJson("myfile")
But for this I have to put myfile in assets folder, and I guess it will need double the disk space.
There are two restrictions why this is impossible now.
Any sqlite database is stored inside a particular path:
'//data/data//databases/'
To get access to any database you have to use a path
You can only get data from assets (or raw) in order to copy to somewhere. This is not possible to manipulate with SQLite without namely 'file' data.
That's why you have to copy data from app resourses into filesystem. Imho, this is ugly but I had not found another solution.
Android default API (Realm uses it) use only the files stored in 'databases' folder.
I want to store a list of 1000 lines which i will write to an array when activity starts. No queries. Just need to rewrite the entire list on some condition and always display the entire list. As SQLite is also only a file , i was wondering what performace benefits does writing a file to storage have over it , if any.
Basically what cases should we use file over SQLite? I know a case - when the data cannot be written in form of table. but if its possible to write data in a table (like a single list) which will then be saved to an array then is file still better.
There are two couple of things both Files system and SQLite introduced in android for storage techniques we can say about each as follows
Files:When you want to store a bunch of data in your application in serialized object format you can store it in to file and save to disc,once after you can deserialize and retrieve data what you want it from
SQLite: It we can use accordingly along with file system but as it have tables we can consider this approach for populating listviews withe limited content(metadata)
For example :You are storing an Object class in to file it might be have large data in it as its not possible/not good an approach to store in db(SQLite) we can store metadata(such as file name what we are storing in file system).
Hence with metadata we can populate listview with SQLite db,and once list is populated with file names we can retrieve respective file from the local storage.
And we have a CursorAdapter in android which will helpful to create a listview with cursor reference.
For your question its bit memory consumption to populate a listview from the file system as there are too many files in storage.More over if it is SQLite data base as we have cursor reference with query we can populate listview using CursonAdapter
I need to download onto my devices some data in multiple files.
Then this data will be copied to application's local db (this is SQLite db, however in future this may be Compact SQL on WInPhone).
What is the best format for such files?
I am considering such possibilities:
SQLited db file - possibly this will be easy to copy to my db. My current prefferance.
JSON format. Maybe not enough compact because column name will be repeating.
CSV - it allows to store only one table but I would prefer have few tables in one file
XML - I do not see any prefferaces over json.
JSON is the most popular, human-readable, easy to use format. There's tons of supporting libraries, native and not, for all OSs. It's fast and reliable. You can easily update the data you pass with it without updating the apps (which you cannot by passing an SQLite database and would be difficult with a CSV file). XML is being slowly deprecated for data communications... but if you see some special advantage with XML (parsing the XML directly, which is not as effective with JSON yet, for example), go for it. I'd choose JSON anyway, it's the current standard and will still be for a long time.
Basically, I'm trying to store some data (~300 rows, ~10 columns) for an android app. This data will not be changed by the app, just used in calculations and stuff.
However, everything I've found online (example) talks about using a database that is created at runtime. I do not want this, the data will be the same every time the app is run.
So is there a way of using a databse like this? (Or any other way of storing data in a table-like fashion?)
Generate the SQLite database as part of your build and keep it in your app's raw resources. Since all you need is the file's path and name to open it, you can still read it fine. Your open helper will still go through onCreate() the first time unless you include the table Android uses for its own bookkeeping, but that should be okay.
Make sure you only open it for reading, and you should be good to go.
Put your custom file in the assets folder under the project root.
To get a inputstream from the file, just do:
context.getAssets().open(file);
In this way you can store your static data in conma separated or any model you want.
If you want the data constantly changing, you can create a temporary file in the SDCard, by accessing and creating a new file under some path at:
Environment.getExternalStorageDirectory()
How about storing this data in raw file under Assets or Res/raw folder. You can either dump this data on the fly in Database or read it and process it [which may be costly]. Dynamic handling may be costly, test it and compare performance.
In my project I have to manage large quantity of static text data(ie no modification, deletion or addition of data, only for displaying and it is based users need). To implement this I have two solutions.
Saving entire text data in to database, to do this I have to keep an xml file that containing text data into asset folder, and during the onCreate of database I have to fetch each text data from file and insert into database.
Saving text data into several xml file in asset, and keep the xml file name into database.
In both case I have to keep database because I want to store some flag element for each text data according to users needs. My question is which is the best method from above? or Is there any other best method?
I think the second option is preferable and better, because in First you have to store all xml files in asset or any other directory then you copy the whole data of those xml files into database (Time consuming) and fill the database with that xml data. (Large size of database probably searching and getting data also time consuming) .
And in your second option you have to just store file name in database. (So no worry of large size database file and you only open that file which is needed so data fetching also easily. your application size is also less)
I think you should create a read only database using Sqlite browser and put in assert folder and when your application execute for the first time the entire database will be copied from assert folder to the Android root database folder .
Here is link to do this ..
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/