Reputation: 89
Hi i need you opinion guys. I use files .dat for saving some info. Is it good way?? I know about SQLite but i don't need much info to save, only one word. I mean each file will have a description, and that description i want to save to file.dat . So should i use .dat or SQLite? Which is better? example of using .dat:
public ImageMetadata(final Context c, final String imageName) {
dataFile = new File(
c.getExternalFilesDir(null).toString() +
File.separator +
imageName +
".dat");
Upvotes: 0
Views: 76
Reputation: 14810
SharedPreferences can be used for in such situations..
See this link for more details please..
SharedPreferences wmbPreference1,wmbPreference2;
SharedPreferences.Editor editor;
//wmbPreference for Shared Prefs that lasts forever
wmbPreference1 = PreferenceManager.getDefaultSharedPreferences(this);
//installsp for Shared Prefs that lasts only just once each time program is running
wmbPreference2 =getApplicationContext().getSharedPreferences("MYKEY",Activity.MODE_PRIVATE);
To save values onto the SharedPreference like this
SharedPreferences.Editor editor = wmbPreference1.edit();
editor.putString("MYKEY", "stringvalue");
editor.commit();
and can retrieve the values like
String tag= wmbPreference1.getString("MYKEY", "default_value_to_be_returned");
where MYKEY is the keyname by which you can identify the value..
You can use putString
,putBoolean
,putFloat
etc as per your needs..
Upvotes: 2
Reputation: 643
Shared Preferences is a good way for you, because you need only one word data:
http://developer.android.com/reference/android/content/SharedPreferences.html
Check this link, I can help you if you have several questions.
Upvotes: 0