Check null before passing to Integer.parseInt
Just after user data is cleared, user preference associated with PREF_KEYBOARD_LAYOUT is always empty. In such case, we might want to return the default value immediately, rather than calling Integer.parseInt(null) and catching NumberFormatException unnecessarily. BUG: 13472379 Change-Id: I8dca9a22780d057013c032bd1f56e730dcada3cemain
parent
a17195224b
commit
f1f5ed542d
|
@ -273,6 +273,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
public static int readKeyboardThemeIndex(final SharedPreferences prefs, final Resources res) {
|
public static int readKeyboardThemeIndex(final SharedPreferences prefs, final Resources res) {
|
||||||
final int defaultThemeIndex = readDefaultKeyboardThemeIndex(res);
|
final int defaultThemeIndex = readDefaultKeyboardThemeIndex(res);
|
||||||
final String themeIndexString = prefs.getString(PREF_KEYBOARD_LAYOUT, null);
|
final String themeIndexString = prefs.getString(PREF_KEYBOARD_LAYOUT, null);
|
||||||
|
if (themeIndexString == null) {
|
||||||
|
return defaultThemeIndex;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(themeIndexString);
|
return Integer.parseInt(themeIndexString);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
|
|
Loading…
Reference in New Issue