1. Are you ready for the Galaxy S20? Here is everything we know so far!

Close app if dialog showing does not work

Discussion in 'Android Development' started by FSchmidt, Mar 18, 2019.

  1. FSchmidt

    FSchmidt Lurker
    Thread Starter

    this is my onBackPressed-Method:

    Code (Java):
    2. @Override
    3. public void onBackPressed() {
    4.     if(drawer != null && drawer.isDrawerOpen(GravityCompat.START)) {
    5.         drawer.closeDrawer(GravityCompat.START)
    6.     } else if(confirmCloseAppDialog != null && confirmCloseAppDialog.isShowing()) {        
    7.         closeApp();
    8.     } else {
    9.         confirmCloseAppDialog.show();
    10.     }
    11. }
    My problem is, that the app does not close if the confirmCloseAppDialog is showing. Where is the problem?

    Kind regards!

  2. GameTheory

    GameTheory Android Expert

    Your closeApp() method needs to have some code that actually closes the app. Can't say much else without knowing what code you have in that method for closing the app.
    #2 GameTheory, Mar 18, 2019
    Last edited: Mar 18, 2019
  3. FSchmidt

    FSchmidt Lurker
    Thread Starter


    closeApp() calles this.finish(). The same method is called if I press the "positive button" in my alertDialog - and it works.

    My alertDialog is a static dialog, which is created in the onCreate-method of my main activity. After the declaration no changes will occur to this dialog.

    Everything works except the app close, if the dialog is showing. What am I missing?

    Edit: Why are you creating an intent in your clos-method?

Share This Page