I am using SharedPreferences
in my android app. I am using both commit()
and apply()
method from shared preference. When I use AVD 2.3 it shows no error, but when I run the code in AVD 2.1, apply()
method shows error.
So what's the difference between these two? And by using only commit()
can I store the preference value without any problem?
apply()
will asynchronously do disk I/O whilecommit()
is synchronous. So you really shouldn't callcommit()
from the UI thread. – michiakigapply()
wins. Therefore, you can useapply()
in lieu ofcommit()
safely if you make sure only one SharedPreferences.Editor is being used by your application. – aoeucommit()
? – QED