Search code examples
androidandroid-alertdialogactivity-finish

Custom Dialog pops up unwantedly


I'm working on an Android App, recently I found out a small bug. Thing is, even If I don't call the Custom Alert Dialogbox function, The Alert Dialog is popping up unwantedly. What must be the reason ?

Providing the code I'm using:-

if (booking.isPayable()) {

                        goToActivity(PaymentActivity.class);
                        postModelSticky(booking);
                        finish();
                    }
                    getBookingConfirmation();

If the condition is true, then go to a activity, else show the dialogBox. getBookingConfirmation() is a function which opens the Alert DialogBox. But Even if the condition is true, The dialog is popped up before the transition happens.


Solution

  • You need to put an else in your code

                       if (booking.isPayable()) 
                       {
    
                            goToActivity(PaymentActivity.class);
                            postModelSticky(booking);
                            finish();
                        }
                        else
                        getBookingConfirmation();