Question

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?

Était-ce utile?

La solution 2

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

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top