我有一个EditText字段,我希望在再次打开应用程序时保存该字段

时间:2012-09-04 23:56:46

标签: android android-edittext save restore

我有一个名为ed的EditText字段。它将存储用户再次启动应用程序时需要的一些文本。我需要保存文本,以便当应用程序再次打开时,它将返回EditText字段。我该怎么做?

2 个答案:

答案 0 :(得分:2)

SharedPreference是一种可行的方式。

SharedPreferences类提供了一个通用框架,允许您保存和检索原始数据类型的持久键值对。您可以使用SharedPreferences保存任何原始数据:布尔值,浮点数,整数,长整数和字符串。这些数据将在用户会话中持续存在(即使您的应用程序被终止)。

以下是实施SharedPreferences的示例。

http://android-er.blogspot.com/2011/01/example-of-using-sharedpreferencesedito.html

http://marakana.com/forums/android/examples/63.html

您可以查看的另一个基本内容是Android的APIDemos中给出的示例实现。 APIDemos示例应用程序具有需要了解的所有基本示例。

答案 1 :(得分:1)

最简单的方法是将它作为键值存储在prefs(putString / getString)中:

http://developer.android.com/guide/topics/data/data-storage.html#pref