I created a custom dialog for my main activity with two buttons, Exit
and Continue
:
public class AgeConfirmationDialog extends Dialog {
public AgeConfirmationDialog(Activity a) {
super(a);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setCancelable(false);
setContentView(R.layout.age_dialog);
// .....
// Find the View objects; checkboxes and buttons logic; SharedPreferences
// .....
}
// .....
}
This is how the dialog is launched from the MainActivity:
AgeConfirmationDialog d = new AgeConfirmationDialog(this);
d.show();
This custom dialog pops out every time the main activity is started, and asks for a age confirmation. I don't want the users to close this dialog using the back button, so I added setCancelable(false)
in the onCreate
method. The Continue
button is disabled until a checkbox is checked. If the Continue
button is pressed, the dialog is dismissed - using setOnClickListener
.
The problem is that I don't know how to dismiss that custom dialog AND finish the main activity when the Exit
button is pressed.
Is it possible to do this from the AgeConfirmationDialog
class by setting a View.OnClickListener
on the Exit
button?