سؤال

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