【问题标题】:Clear application shared preference programmatically? [duplicate]以编程方式清除应用程序共享首选项? [复制]
【发布时间】:2018-09-10 07:46:16
【问题描述】:

我正在创建一个使用共享首选项的应用程序,出于测试目的,我必须刷出该数据(首选项),那么如何以编程方式清除 Android 中的共享首选项?

【问题讨论】:

    标签: android sharedpreferences reset


    【解决方案1】:

    只需一个SharedPreferences.Editor.clear(),然后是一个commit()

    【讨论】:

      【解决方案2】:
      context.getSharedPreferences("PREF", 0).edit().clear().commit();
      

      【讨论】:

      • 请在此答案中添加更多上下文,以便 OP 了解解决方案。例如。 “'PREF' 和 '0' 参数是什么?”
      【解决方案3】:

      试试这个

      SharedPreferences preferences = getSharedPreferences("PREFERENCE",Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = preferences.edit();
      editor.clear(); 
      editor.commit();
      

      【讨论】:

        【解决方案4】:

        清除偏好SharedPreferences.Editor.clear().apply() 检查here回答的相同问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-06-11
          • 2019-02-18
          • 1970-01-01
          • 2020-11-28
          • 1970-01-01
          • 2018-11-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多