I want to handle the back press event when showing a popup window in android. I do like this. In the fragment:
@Override
public boolean onBackPressed() {
if (backPressStrategy == BACK_PRESS_PLAN_A) {
if (guideDialog != null) {
guideDialog.dismiss();
}
closeFlashPay(REQ_CLOSE_FLASH_PAY_AND_FINISH);
return true;
} else if (backPressStrategy == BACK_PRESS_PLAN_B) {
if (guideDialog != null) {
guideDialog.dismiss();
}
getActivity().finish();
return true;
} else {
return false;
}
}
And in the Activity, I do like this
@Override
public void onBackPressed() {
PayBaseFragment contentFragment = (PayBaseFragment) getSupportFragmentManager().findFragmentByTag(TAG_CONTENT_FRAGMENT);
if (contentFragment != null && contentFragment.onBackPressed()) {
return;
}
super.onBackPressed();
}
The problem is, the first time when I pressed back button, the popupwindow just disappeared and the override onBackPressed method was not invoked. Unless I press back button two times. I show my popup window like this
guideDialog.showAtLocation(getActivity().getWindow().getDecorView(), Gravity.CENTER, 0, 0);
Thanks for help