Android: different ways of storing and reading variable values? - java

I have about 16 variables in which the values need to be saved for later recall / editing. I've tried SQLite Database, since I am a novice at Android, it is just too hard for me. I will have to come back to SQL later. Are there any other ways to store these values for later recall / editing? Thank you! Maybe link me to a tutorial if possible? :-)

You might try using SharedPreferences.

SharedPreferences is another choice. Here is a very simple example
how to use it.
Storing 16 variables using SharedPreferences will make your code looks long. I advise you to try harder with SQlite database.

Related

Saving data to file or database

I'm starting to work on a new Java desktop app that should help me and my colleagues learn vocabulary. It will contain around 700 words, some texts (that point to the words contained in them) and maybe some images (not sure about that part yet). The data will never change and I want the program to be able to run offline.
The question is: Should I use database, text file or serialize the data into file? Or perhaps if there is any other option I don't know about? If you could explain your choice in detail I would be glad.
If the data never changes and is only 700 words it would probably be easiest to use a file.
If your data was a bit more complex and had many fields and was being constantly updated, a database would be more preferable but a csv file could still be used.
Since you want to access this data offline and data never changes, I think the best option would be to just use text file, which will be more efficient in terms of access and speed.
Keep all the data in memory as Serializable Java objects, and store them serialized when your application is not running. Evaluate airomem - really nice solution that would perfectly work for you.

How should I save a dictionary database with java?

When I google "how to make a dictionary", it gives me a great measure of the explanation of "make", which is very helpful. But I need something else, so I put this question here.
I want to make a small project. I want to make a dictionary with java or android. But I don't know how should I organize the words. I have considered a JSON file, a XML file or I can also simply output all the words as ojbects into a file. Could anyone please give me some adivce?
Assuming that you want to be able to read (quickly) values from your dictionary, and maybe update values or create new values then I suggest that you store your dictionary in a Database. For a simple Java database I suggest that you use an embedded Derby Database.
see http://db.apache.org/derby/

What's the best way to go about saving data to file?

I'm writing an Android application that needs to store dates and time into file and then read from this file and display it in an activity. What is the best way to go about this? any common practices about this?
thanks!
You can use SQLite database which allows you use of date functions.
http://www.sqlite.org/lang_datefunc.html
Read here aboute SQLite date and timestamp functions.

Best way to save a little amount of data

I'm currently developing an Android application where OAuth will be in use. In order to use OAuth, I need to be able to save the consumer's private key to access the protected resources. My question is, where would I want to save this tiny piece of data? I know that for most Android applications, data would be stored in a SQLite database. But for only a little bit of information, a string containing random letters and numbers, would SQLite be the best way to go? Or would it just be better to write the data to a file and save it on the file system? I don't know what the best practice for this would be, so hopefully I'll be able to get some insight.
Thanks a bunch guys!
You have a lot of choices:
http://developer.android.com/guide/topics/data/data-storage.html
However, if you just want to save one String (the OAuth key), I would suggest shared preferences. Example:
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("oauthKey", yourOAuthKey);
// Commit the edits!
editor.commit();
I would save it in a file on the internal storage or in shared preferences.
Never the less you should encrypt the key for security reasons! On a rooted oder developer device it is no problem to access any file on the system.
SharedPrefs is much easier to work with than an sqlite database - especially for something so simple as you describe.
I guess a SharedPreference would do just fine.

Saving and Adding to A List (Android)

Plain and, hopefully simply...
-What I would like to do is make a list of strings.
-I would like to add to this list while in the application.
-Finally, I want to get each String from this list.
This must be saved somehow so that when you close it and open it back up, the list will save...
How should I get around to this? SharedPreferences? An SQL Database? What should I use to accomplish this?
I vote SharedPreferences since it will be faster and will persist throughout the life span of the application.
If you need to have the saved data made available during the next time the app is run, you will most likely want to use a DB

Categories