Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android内存中保存多个字符串以供以后使用_Android_Sql - Fatal编程技术网

在Android内存中保存多个字符串以供以后使用

在Android内存中保存多个字符串以供以后使用,android,sql,Android,Sql,我有一个应用程序,每次我使用它时都会生成五个字符串,我希望这些字符串保存起来,以便以后使用,即当我再次打开并运行该应用程序时。当我第二次使用该应用程序时,我想将新的五个Sting与第一次运行该应用程序时生成的前五个字符串一起保存以备以后使用。直到我说出这五根弦的10组 我很困惑什么是最好的方法,内存,sql数据库,等等。有人能给我举一个好的例子来说明这方面的最佳实践吗。我对sql数据库的经验非常有限。Sqlite在我看来是最佳实践 如果你有固定数量的字符串,你也可以使用SharedReferen

我有一个应用程序,每次我使用它时都会生成五个字符串,我希望这些字符串保存起来,以便以后使用,即当我再次打开并运行该应用程序时。当我第二次使用该应用程序时,我想将新的五个Sting与第一次运行该应用程序时生成的前五个字符串一起保存以备以后使用。直到我说出这五根弦的10组


我很困惑什么是最好的方法,内存,sql数据库,等等。有人能给我举一个好的例子来说明这方面的最佳实践吗。我对sql数据库的经验非常有限。

Sqlite在我看来是最佳实践
如果你有固定数量的字符串,你也可以使用
SharedReferences

Sqlite在我看来是最好的做法
如果你有固定数量的字符串,你也可以使用
SharedReferences

你可以使用
SharedReferences
来存储字符串

你可以使用
SharedReferences
来存储字符串

Android实际上为你提供了一系列的存储机制,比如

  • 共同偏好
  • Sqlite
  • 文件
  • 外部或内部目录

  • 看看这些:Android实际上为您提供了广泛的存储机制,比如

  • 共同偏好
  • Sqlite
  • 文件
  • 外部或内部目录

  • 请从android网站上查看以下内容:

    要保存:

    // We need an Editor object to make preference changes. 
    // All objects are from android.context.Context
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean("silentMode", mSilentMode);
    
    // Commit the edits!
    editor.commit();
    
    要加载:

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    boolean silent = settings.getBoolean("silentMode", false);
    

    从android网站:

    要保存:

    // We need an Editor object to make preference changes. 
    // All objects are from android.context.Context
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean("silentMode", mSilentMode);
    
    // Commit the edits!
    editor.commit();
    
    要加载:

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    boolean silent = settings.getBoolean("silentMode", false);