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?

Was it helpful?

Solution 2

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top