Which file type should I use to store database data - android

I'm developing a little Android app which is going to be offline, and I need to store the SQLite base's data into a file, that I want to put into the apk's resources, I could use XML or JSON files, but I was wondering if there weren't a better solution.
Thanks in advance :)

If I understand you right you have some prepared data to include in app to use.
If you don't want to parse xml, json or raw file every time you need it in the app you could:
1. Parse the file and put contents into SQLite database on the first run of the app.
Then you can use SQLite to query for data.
You can check if this is first run by checking boolean flag in SharedPreferences upon start of application (in onCreate of your main activity or in Application class)
2. If data is not very big you could parse it once and keep it in memory in your custom data structure.
You can create a singleton to query for this data and parse it in case it is not loaded yet.

Related

Android: Best way to keep static content in application

I want to build an android application which has static content. I dont know where should I keep my static content. Shall I keep it in my xml file or use sqlite db. Or shall I keep my data in xml file and create the table when the application loads . Data wont change much over the period of time and only fetch operation has to be performed on the data.
It depends on the data which you want to store..If it is some small key value king of data use
SharedPreferences otherwise you can use sqlite database if you relational data..Files are generally used to store non-relational data.
Refer http://developer.android.com/training/basics/data-storage/index.html. to learn how to implement each of these techniques.
Personally, I'd opt for an XML file structure. The data handling code will be comparable but updates from the host database will be infinitely more efficient. Good luck with your project.

Clear Cash in android application

I have android application, I use SQLite data base in my application, I have a question about data base in setting -> application manager if I select clear data or clear cash, our data base deletes, but I need data base. For example user remove data base suddenly after that my program does not work, my program is related to data base, how do I do, how can I resolve my problem?
You will need to find some way to backup your database to the SD card. You could just dump it as a CSV-type file, which would exactly mimic the structure of a database, or else create some other kind of format which would work better for you. And then in the case that the database is cleared, you will need to parse the text file you created as the backup, and put it all back into the database.

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.

JSONObject write to temp file

I am currently working on Android platform and developing small application. In my application I need one temporary file which contains my all JSON objects. I want to create new temp file and access to that temp file. What is the proper way to create file and storing data in it. Thanks in advance!
If you're looking to have the data persist across application launches, so that you can retain data even if the application is killed, then You probably don't want to keep it in a file, and you will want to use SharedPreferences. Then, just store whatever JSON string you want to keep as a String.
If you just need the JSON information to be stored for that use only, Keep the objects in some sort of Array or List data structure.

Where to store json datas instead of using sqlite in android?

I am accessing the datas from json, storing the datas from json in sqlite and then retrieving it and display them on screen. It takes too long time for this process. Which is the better way to reduce the time consumption instead of storing and retrieving the datas from sqlite? Can anyone help me in this issue?
You can store the JSON as plain text in a file.
A nice place to put them would be your application's cache directory.
https://developer.android.com/reference/android/content/Context.html#getExternalCacheDir()
https://developer.android.com/reference/android/content/Context.html#getCacheDir()
You can store a JSON Data in a File or in a Shared Preference. Check Saving data in android training
I also use the file system to store json. It can be easier for debugging as you can have the json.tostrong methods indent the json yo make it easier to read using the android file browser.
i make a filesystem class that accepts and returns json so apps just see the file system as a json store.

Categories

Resources