Invalidate the options menu on visibility changes.
Currently, we set the mShowOptionsMenu when the visibility of the
fragment changes. However, it may be possible to update this after the
options menu has been created but before the menu is prepared, which
would lead the menu to be in an inconsistent state.
By invalidating the options menu, we are guaranteed it will be
re-created.
Bug: 5335885
Change-Id: I1183d898d6e4867845aa04e054273bf271695d02
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 2d93a98..0628db4 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -337,7 +337,15 @@
@Override
public void onVisibilityChanged(boolean visible) {
- mShowOptionsMenu = visible;
+ if (mShowOptionsMenu != visible) {
+ mShowOptionsMenu = visible;
+ // Invalidate the options menu since we are changing the list of options shown in it.
+ Activity activity = getActivity();
+ if (activity != null) {
+ activity.invalidateOptionsMenu();
+ }
+ }
+
if (visible && isResumed()) {
refreshData();
}