What is the most appropriate way to store some structured texts?The texts will be a collection of "books".each book contains a collection of articles,and each article has a title and a body.
The ways i could think of are:
create a database using sqlite
write an xml file in assets
put them into res/value/string
use java string
which method is the best for my situation?is there a better way other than those ive listed above?
Thanks in advance.
=========================
edit: Yes,the data can be regarded as static.
XML, or any other format you prefer in res/assets is the preferred way, if your data is static (it won't change).
If you want to work with dynamic data gathered from a webapp for example, then you should use the built in SQLite database.
If you're looking for persistent storage then I would suggest a small SQLite database. You could also store it in XML documents and then use a ContentProvider to abstract your access to the books, but then you would have to write the I/O and XML-parsing operations yourself.
Related
the scenario is that -- in my application client would make dynamic edit text (of which i m not sure ), but i want to store all the information he creates. All other part have been done.
I just want to know which is the best way to store them in File OR in Database.
As if some says in Database, i want to know how?
and if in File, why?
I will encrypt and decry pt the data too.
Any help would be appreciable.
Thanks in advance.
Store the data in a database. If you're doing Android development, simply use SQLite - http://www.sqlite.org/.
There are many reasons not to store the data on the file system:
It is easier to query a database than a file system. You can quickly and easily answer questions like "How many records do I have?" or "How many items in a given category do I have?"
If you do this in the file system, you'll have to write your own code around querying.
SQLite has strong data types that enforce a schema. If you just write to a file, you'll have to ensure an ID is an integer etc. The database can do this for you.
From my experience when writing files to the file system, I've always ended up with orphaned files. You write them and then forget they are there and they never get deleted. It's annoying. With a database you can easily assess the state of the database and remove old/unused records.
In my android application I have to store some application settings and some user information within the phone.
I can go for the shared preference option explained in this DOCUMENTATION.
But wondering if I can store data as objects wise within the phone. I found this Stackoverflow Question regarding saving serialized objects in files and bit not sure of any issues if I go with this way to store persistent data.
Also would like to know what the best way to deal with insert/delete/update and read with XML files in android. Would appreciate any guidance. Thanks in advance...!!!
If it is only a small amount of data you need to store, then go with the built-in shared preferences, that is what the functionality is there for. SQLite and OrmLite are a bit heavyweight in this situation IMO. Even if you want to handle the data as Objects; in which case I would serialise to / deserialise from JSON or XML stored in text files and handle the insert/update/delete on the deserialised objects in your model.
If you want to persist some objects I think you should use SQLiteDatabase, it would be a more cleaner solution than using serialization in files. You will indeed need to write some extra code for your Database but you will end up with a cleaner implementation in my opinion. You could also be using OrmLite for Android which is pretty robust and easy to use if you have some basic orm knowledge.
I wanna write an android application which will store and retrieve large amounts of text data. I wanna store text in paragraph wise.I need to manipulate this text data in an efficient way. What will be the best way for doing this?
I think the best way is to save all data inside a file. And save this file to specified location in sdcard. If you are saving data inside a file you will get same format as you saved(e.g Paragraph wise in your case).And you can delete file when ever you want.
I found this may this help you to solve your issue
SharedPreferences is apparently implemented internally as an XML file which is serialized and deserialized in full on update. And it's a Key-Value store with no index. So use that only for simple data associated with your app. Any more than 50 keys and you've probably overdone it.
ContentProvider is intended for sharing data across applications. You've explicitly said you don't want to do that.
SQLiteDatabase is intended for individual apps to store data, and provides a lot of flexibility to store and index data in different ways. I personally use it to store logs in one of my apps. I'd recommend that route.
See this discussion for more details
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 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!