From 6c8136d1574f7e72eae951ee80f885d008c8e4c4 Mon Sep 17 00:00:00 2001 From: Satoshi Kataoka Date: Fri, 7 Jun 2013 11:25:27 +0900 Subject: [PATCH] Fix possible NPE Bug: 9314901 Change-Id: Id80f59df38ae72766b097fd1c23326fedd302439 --- .../android/inputmethod/latin/SettingsFragment.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java index 7225cd6bf..8365cce3a 100644 --- a/java/src/com/android/inputmethod/latin/SettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java @@ -32,6 +32,7 @@ import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; +import android.util.Log; import android.view.inputmethod.InputMethodSubtype; import java.util.TreeSet; @@ -45,6 +46,7 @@ import com.android.inputmethodcommon.InputMethodSettingsFragment; public final class SettingsFragment extends InputMethodSettingsFragment implements SharedPreferences.OnSharedPreferenceChangeListener { + private static final String TAG = SettingsFragment.class.getSimpleName(); private static final boolean DBG_USE_INTERNAL_USER_DICTIONARY_SETTINGS = false; private ListPreference mVoicePreference; @@ -246,7 +248,14 @@ public final class SettingsFragment extends InputMethodSettingsFragment @Override public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) { - (new BackupManager(getActivity())).dataChanged(); + final Activity activity = getActivity(); + if (activity == null) { + // TODO: Introduce a static function to register this class and ensure that + // onCreate must be called before "onSharedPreferenceChanged" is called. + Log.w(TAG, "onSharedPreferenceChanged called before activity starts."); + return; + } + (new BackupManager(activity)).dataChanged(); final Resources res = getResources(); if (key.equals(Settings.PREF_POPUP_ON)) { setPreferenceEnabled(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,