Pregunta

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!

¿Fue útil?

Solución

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.

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!

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top