if sp.clear(); and sp.commit(); is executed to clear the values of SharedPreferences.

It will only clear the values for the particular instance that was used to initialize the SharedPreferences?

It will not clear whatever values that was stored on SharedPreferences by other application?

有帮助吗?

解决方案 2

Use sp.remove().The remove() method will remove the shared preference.

其他提示

Calling sp.clear(); will remove only one shared preferences file's values.

When you use a method to get access to shared preferences, you specify the file name using getSharedPreferences (String name, int mode) method. All the preferences in this file only will be removed.

If you use PreferenceManager.getDefaultSharedPreferences(context) to get access to your shared preferences, it will still remove values from only one file which is the default file for the context you specified in the parameter.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top