How To Save A Couple of Strings To Internal Storage in Android? - Stack Overflow
How To Save A Couple of Strings To Internal Storage in Android? - Stack Overflow
Asked 5 years, 11 months ago Active 5 years, 11 months ago Viewed 1k times
I'm trying to develop a simple notepad on android. But I don't know how to save my
notes(strings) to internal storage(or to an SQL database if it's faster). if I used internal storage
2 would I be able to save a couple of strings and get them back? I'm a beginner to mobile
application development and this is my first project. so I'd really appreciate it if you could
show me a sample code so I can learn from it. Thanks!
1 if information is small better use the shared preferences other go for sqlite db..
examples.javacodegeeks.com/android/core/database/sqlite/… – sri Aug 29 '13 at 17:44
2 Answers
A database is an option, therefore you'll definitively have to read the follow page, that helped
me a lot. There is also some sample code in it.
2
http://www.vogella.com/articles/AndroidSQLite/article.html
In paragraph 9.7 is the full code for adding, editing and deleting records...
An other option is saving the string in an .txt file and save that on the storage. Than this
might bring you further:
Good luck!
thanks! I'm going to try both options. saving strings in a text file sounds great, but is there a way to
By using our site, youitacknowledge
save that you– have
in internal storage? readWickramaratne
Pankaja and understand Sep
our Cookie
4 '13 atPolicy
2:36 , Privacy Policy, and
our Terms of Service.
stackoverflow.com/a/9306962/2394403 this link might help you with that issue... – Beko1997 Sep 4
'13 at 17:55
To store:
0
SharedPreferences sharedPref = getSharedPreferences("SomeName",
Context.MODE_PRIVATE);
Editor editor = sharedPref.edit();
editor.putString("String1", value); // value is the string you want to save
editor.commit()
To retrieve:
defaultValue ---- in case the key is not available, this is the retrieved string