diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java index c31a372ee..1b473dd38 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java @@ -431,45 +431,55 @@ protected void onDestroy() { @Override public void onBackPressed() { - // Get Preference about double back button press to exit - boolean prefShallUseDoubleBackPressToExit = PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean(getString(R.string.key_use_double_back_button_press_to_quit), - true); + if (isNavigationViewOpen()) { + // The main navigation menu is open - if (mDoubleBackButtonPressedOnce || !prefShallUseDoubleBackPressToExit) { - // BackPress button has already been pressed recently OR shall not use double back press to exit + // Close the main navigation menu + super.onBackPressed(); + + } else { + // The main navigation menu is closed - // - // Do not show the Toast anymore - // + // Get Preference about double back button press to exit + boolean prefShallUseDoubleBackPressToExit = PreferenceManager.getDefaultSharedPreferences(this) + .getBoolean(getString(R.string.key_use_double_back_button_press_to_quit), + true); - if (mToast != null) { - // There is a Toast + if (mDoubleBackButtonPressedOnce || !prefShallUseDoubleBackPressToExit) { + // BackPress button has already been pressed recently OR shall not use double back press to exit + // // Do not show the Toast anymore - mToast.cancel(); + // - } else { - // There is no Toast + if (mToast != null) { + // There is a Toast - // NTD - } + // Do not show the Toast anymore + mToast.cancel(); - // Perform BackPress - super.onBackPressed(); + } else { + // There is no Toast - } else { - // BackPress button has been pressed for the first time AND shall use double back press to exit + // NTD + } + + // Perform BackPress + super.onBackPressed(); - // Notice that button has been pressed once - this.mDoubleBackButtonPressedOnce = true; + } else { + // BackPress button has been pressed for the first time AND shall use double back press to exit + + // Notice that button has been pressed once + this.mDoubleBackButtonPressedOnce = true; - // Show a message to explain that user must press again to exit - mToast.show(); + // Show a message to explain that user must press again to exit + mToast.show(); - // After two seconds, it is not more considered as already pressed - mHandler.postDelayed(mResetDoubleBackPressedStatusRunnable, - 2000); + // After two seconds, it is not more considered as already pressed + mHandler.postDelayed(mResetDoubleBackPressedStatusRunnable, + 2000); + } } }