Make sure to close popup before orientation changes..
to avoid window leak.
Even with this CL there'll be an error message shown on orientaion changes,
but it's a framework issue that even the framework Spinner has.
(bug filed)
Bug 5209304
Change-Id: I0b8335e9b875a23c48b19bf65462d037c0dba6c1
diff --git a/src/com/android/contacts/detail/ContactDetailFragment.java b/src/com/android/contacts/detail/ContactDetailFragment.java
index 603d2fa..197ba4f 100644
--- a/src/com/android/contacts/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/detail/ContactDetailFragment.java
@@ -211,6 +211,8 @@
private boolean mIsUniqueNumber;
private boolean mIsUniqueEmail;
+ private ListPopupWindow mPopup;
+
public ContactDetailFragment() {
// Explicit constructor for inflation
}
@@ -235,6 +237,7 @@
@Override
public void onPause() {
+ dismissPopupIfShown();
super.onPause();
}
@@ -288,10 +291,6 @@
return mView;
}
- protected View inflate(int resource, ViewGroup root, boolean attachToRoot) {
- return mInflater.inflate(resource, root, attachToRoot);
- }
-
public void setListener(Listener value) {
mListener = value;
}
@@ -1006,23 +1005,31 @@
*/
private void showListPopup(View anchorView, ListAdapter adapter,
final AdapterView.OnItemClickListener onItemClickListener) {
- final ListPopupWindow popup = new ListPopupWindow(mContext, null);
- popup.setAnchorView(anchorView);
- popup.setWidth(anchorView.getWidth());
- popup.setAdapter(adapter);
- popup.setModal(true);
+ dismissPopupIfShown();
+ mPopup = new ListPopupWindow(mContext, null);
+ mPopup.setAnchorView(anchorView);
+ mPopup.setWidth(anchorView.getWidth());
+ mPopup.setAdapter(adapter);
+ mPopup.setModal(true);
// We need to wrap the passed onItemClickListener here, so that we can dismiss() the
// popup afterwards. Otherwise we could directly use the passed listener.
- popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ mPopup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
onItemClickListener.onItemClick(parent, view, position, id);
- popup.dismiss();
+ dismissPopupIfShown();
}
});
- popup.show();
+ mPopup.show();
+ }
+
+ private void dismissPopupIfShown() {
+ if (mPopup != null && mPopup.isShowing()) {
+ mPopup.dismiss();
+ }
+ mPopup = null;
}
/**