Fix bug #13794200 Settings crash when screen is locked and Power Usage...
...Settings is launched with an Intent
- fix the NPE by checking if mSearchMenuItem / mSearchView references are null
Change-Id: I7518c8360af88a20df780be8cb89360a26cdb8d0
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 5aa2737..62b37af 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -185,6 +185,8 @@
private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
+ private static final String EMPTY_QUERY = "";
+
private static boolean sShowNoHomeNotice = false;
private String mFragmentClass;
@@ -577,8 +579,17 @@
}
}
}
- outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, mSearchMenuItem.isActionViewExpanded());
- outState.putString(SAVE_KEY_SEARCH_QUERY, mSearchView.getQuery().toString());
+
+ // The option menus are created if the ActionBar is visible and they are also created
+ // asynchronously. If you launch Settings with an Intent action like
+ // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
+ // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
+ // menu item and search view are null.
+ boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
+ outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
+
+ String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
+ outState.putString(SAVE_KEY_SEARCH_QUERY, query);
}
@Override