/**
  * When the back key is pressed while the popup is visible, close the popup and keep the activity
  * open
  */
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if ((keyCode == KeyEvent.KEYCODE_BACK)) {
     if (keyCode == KeyEvent.KEYCODE_BACK) {
       if (mPopupWindow != null && mPopupWindow.isShowing()) {
         mPopupWindow.dismiss();
         return true;
       }
     }
   }
   return super.onKeyDown(keyCode, event);
 }