gpt4 book ai didi

java - 清除 SharedPreference 中的单个变量

转载 作者:行者123 更新时间:2023-12-02 06:50:53 26 4
gpt4 key购买 nike

我的应用程序中保存了以下 SharedPreference:

editor.putString("strInfName", nameOfInf.getText().toString());
editor.putFloat("dblTollAmount", Float.parseFloat(tollAmount.getText().toString()));

如何只清除一个变量而不是同时清除两个变量?

editor.clear(); 会清除所有变量,但我只想清除 strInfName

这行得通吗:

editor.edit().remove("strInfName").commit();

最佳答案

来自docs :

public abstract SharedPreferences.Editor remove (String key)

Added in API level 1 Mark in the editor that a preference value should be removed, which will be done in the actual preferences once commit() is called.

Note that when committing back to the preferences, all removals are done first, regardless of whether you called remove before or after put methods on this editor.

Parameters key The name of the preference to remove. Returns Returns a reference to the same Editor object, so you can chain put calls together.

关于java - 清除 SharedPreference 中的单个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18038910/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com