Android Store to external or to SharedPreferences - android

I have an application which should to work without offline connection too. That is why I have to store the data when I could downloaded at first. I do some modifing, save and after when I can connect to the internet I refresh the data.
The data is an xml file.
Which would be the best. To store my xml on the external storage or it is better if I use SharedPreferences?

Which would be the best. To store my xml on the external storage or it
is better if I use SharedPreferences?
Generally it depends on data character. If your data are structured (represends certain objects) you should use SQLite database to store them. If not, try to think about mentioned SharedPreferences.
Both approach we can mark as working but both have different advantages and disadvantages.
For example if you'll store data on external storage, there are no quarantied a security. This is dangerous in a case if your data are sensitive.
But if you'll use internal storage, certain amount of security you'll get. So you need to choose a solution based on more requirements.
Your actual case (XML) it seems that SQLite would be very good, efficient a safe solution because usually XML represents objects with properties and on on other hand, database represents objects as tables.

Related

Android Persistent Storage

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.

Best Possible way to Store Data (Lot of Strings with Images) in android application

I am trying to build a application which will be a Ebook kind of (Lot of theory & diagrams) will be there.
Now what i want to know is that since there are many ways of storing the data which one will be the best
Storing in Database
XML
Or simple text files
I am very concerned about the security of the data as well. Since this will be a paid app, i want the data to be secured and also be fast and convenient.
Also, I thought of converting the doc files (Data) in to epub format & then use epub api's to access the data and show it on the android app screen, will this be a gud idea to go for? as compared to the above ways?
Which one will be more secure, fast, flexible & easy!
It depends on how you will access to this data. If you will store in xml you will must to read the whole file from the start to access to chapter (or load to memory, for example). It's not good idea if you will store big data.
Storing in SQL faster. You can gain access to any chapter. You don't need to read all data, like in xml.
Simple text file has the same problem like XML (xml is textfile).
The only one way to secure you data - encrypt it. If user will get root on their device, he will gain access to your files and databases. There is no meaning where you will store your data.
Depends on what is more important to you - speed or security.
Speed
Definitely SQLite, it isn't exactly the cleanest, but definitely the fastest way.
Security
Custom files which are encrypted - it will take a while to read the whole file and then decrypt it in order to display it, but you can be sure that the attacker will access the files encrypted and without the knowledge of the encryption - those data would be useless to him.
EPUB
If you're concerned about security then don't, unless you know how to apply DRM...and that is not a way to go honestly.
I think that the best way to store big amount of data is database. In Android it is sqlite database. I recommend you to put all your text data into sqlite database. You can structure it in easy and beautiful way. Then put your images into assets folder and store the pathes to the the images in database.
Advantages of database solution:
Always well structured data
Easy way to update data with version control system.
You can store and get fast accesses to really big amount of data.
You can use encryption to protect your data.
Disadvantages
It is more complicate to write good code for database solution then for XML or JSON one.
P.S If you will decide to use XML I recommend you to change it to JSON. It is faster and easier to use.
Which one will be more secure, fast, flexible & easy!
Secure: It mainly depends on encryption system.
Fast: SQLite, you can read some advantages of SQLite here Android Performance : Flat file vs SQLite
Flexible and easy: Storing the encrypted files in internal storage is a flexible and easy way. I think it is secure enough. Here you can get some android security tips about storing data http://developer.android.com/training/articles/security-tips.html#StoringData
for saving little data you can use xml for strings but you lose fast loading factor
sqlite is good for almost every purpose, but Security

Saving GPS points without database

Can I save GPS points in android without using database?
I want first to track user's position then to reverse his track, so I need to save tracked points in order to traverse them.
You can always write your data to a file, following whatever format suits you (XML, JSON, or your own custom-made format)
See Using internal storage and Using external storage guides.
Depending on the size of the resulting file, it might be better to use External storage, which often has more space.
Also, maybe you have some specific reasons to not use a database, but I think using SQLite is easier to manage than file for storing data. See Using database guide for more information

best away to save strings on android

What is the best way to save several strings on android?
I thought that the best way was SQLite, but in this case when I close my app the data will be save? When I open the app again the data will be there? Or should I use txt files to save it and restore it?
It depends on what you are trying to do with the file. You have several options when you are saving data: internal storage, external storage, caching, SQLite database, or networking. If you are just saving a couple Strings I think that creating a database is overkill. I would look at saving the files to internal storage. You can write the Strings to a file then retrieve that file when you restart the app.
You don't want to make things more complicated than they need to be. Keep it simple. If you are saving a couple KB worth of data, use a file. If you are getting into MB worth of data, and need to query specific data sets, then look at a database. You have to remember that databases take a lot of time and resources, not only to set up, but to maintain.
Here is the Android document that outlines the different ways to save data to a device: http://developer.android.com/guide/topics/data/data-storage.html
This should really help you understand what is going to be best for you.

Most efficient way to store and retrieve large amounts of text data in android

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

Categories

Resources