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 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!
Asked
Active
Viewed 2,242 times
2
-
1if information is small better use the shared preferences other go for sqlite db.. http://examples.javacodegeeks.com/android/core/database/sqlite/sqlitedatabase/android-sqlite-example/ – srinivas Aug 29 '13 at 17:44
-
if you plan to use sqlite db just refer this http://developer.android.com/training/notepad/index.html#preparing – Aravin Aug 29 '13 at 17:52
2 Answers
2
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.
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 save it in internal storage? – Pankaja Wickramaratne Sep 04 '13 at 02:36
-
http://stackoverflow.com/a/9306962/2394403 this link might help you with that issue... – Beko1997 Sep 04 '13 at 17:55
0
You can save it in shared preference if it is not too big.
To store:
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:
SharedPreferences sharedPref = getSharedPreferences("SomeName", Context.MODE_PRIVATE);
String retrievedString = sharedPref.getString("String1", defaultValue);
"SomeName" ---- the preference name
"String1" ---- key for the string you want to store/retrieve
defaultValue ---- in case the key is not available, this is the retrieved string

sjdutta
- 376
- 1
- 5