0% found this document useful (0 votes)
45 views

How To Save A Couple of Strings To Internal Storage in Android? - Stack Overflow

To save a few strings to internal storage in Android, there are a few options: 1) Use shared preferences to save small strings. You can save strings by getting a shared preferences editor and committing the strings with a key. To retrieve, use the key to get the string value. 2) Use SQLite database which is faster for larger data. Sample code is provided in Android's Notepad tutorial. 3) Save strings to a text file and write this file to internal storage. Code samples are provided to write files to external storage which can also be used for internal storage. The best approach depends on the amount of data, with shared preferences suitable for a few small strings, and databases

Uploaded by

babom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

How To Save A Couple of Strings To Internal Storage in Android? - Stack Overflow

To save a few strings to internal storage in Android, there are a few options: 1) Use shared preferences to save small strings. You can save strings by getting a shared preferences editor and committing the strings with a key. To retrieve, use the key to get the string value. 2) Use SQLite database which is faster for larger data. Sample code is provided in Android's Notepad tutorial. 3) Save strings to a text file and write this file to internal storage. Code samples are provided to write files to external storage which can also be used for internal storage. The best approach depends on the amount of data, with shared preferences suitable for a few small strings, and databases

Uploaded by

babom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

How to save a couple of strings to internal storage in android?

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!

android save storage internal

asked Aug 29 '13 at 17:36


Pankaja Wickramaratne
13 3

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

if you plan to use sqlite db just refer this


developer.android.com/training/notepad/index.html#preparing – Aravin Aug 29 '13 at 17:52

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:

Write a file in external storage in Android

Good luck!

edited May 23 '17 at 11:44 answered Aug 29 '13 at 17:47


Community ♦ Beko1997
1 1 103 1 9

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

You can save it in shared preference if it is not too big.

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:

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

answered Aug 29 '13 at 17:56


sjdutta
356 1 5

You might also like