Android – second parameter in preferences.getInt in android

android

int minMagIndex = prefs.getInt(Preferences.PREF_MIN_MAG, 0);
if (minMagIndex < 0)
minMagIndex = 0;
int freqIndex = prefs.getInt(Preferences.PREF_UPDATE_FREQ, 0);
if (freqIndex < 0)
freqIndex = 0;

What is the second parameter in prefs.getInt ?

why is this if condition check done ?

Best Answer

The second parameter is the default fallback, if not preference "PREF_MIN_MAG" can be found. I.e.: "assign minMaxIndex the value of preferences 'PREF_MIN_MAG', if that exists. If it doesn't, use 0".

After that, there's a check to see if the value that was found in preferences was less than 0. If it is, it's being reset to 0.