What is the best way to save null value of data type "Integer" in Shared Preferences. I can find putInt(which does not allow null values); but no putInteger.
Kindly suggest the proper way to achieve this.
What is the best way to save null value of data type "Integer" in Shared Preferences. I can find putInt(which does not allow null values); but no putInteger.
Kindly suggest the proper way to achieve this.
As long as the putInt
function only accept the int
primitive type as its argument. So I think you can't put null value in there.
My suggestion is you should try putString
instead of it. And when you get the value from SharePreference
, just parse it into int
value.
My solution:
String value = mSp.getString("YOUR_KEY", "");
if (value.equals("") {
// Which means it is 'null' number
} else {
int number = Integer.parseInt(value);
}