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
Related
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.
My app collects data which it stores in arrays, and I need to be able to access the data from outside the app. The tablet I am using has no SD card, so I'm thinking the best way to transfer data would be to save to 'external' system memory. I have found tutorials to save data on internal storage and for specific data types like pictures onto SD cards, but I can't figure out how to write an arbitrary file to an arbitrary location. Thanks.
This sounds like a perfect time to use a SQLite database. Android comes with SQLite support built in so its easy to set up. You can just create a database and store your array data there (you can even store pictures too as a byte[]). There are a number of tutorials that show how to do this. Here is 1 and 2. It should be pretty easy from there.
I'm not sure that you can write to an arbitrary place on the Android system. You could write to a file in /data/data// and then email that file to yourself.
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.
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.
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