I was wondering how you would have a warning appear when the user tries to exit the app? So this includes if they are pressing the back button too. What would be the best way to do this?
I have seen this done on some mainstream games.
you may add onBackPressed() in your Application subclass to intercept the back button:
public static void onBackPressed(final Activity activity) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.on_back_button_title);
builder.setMessage(R.string.on_back_button_message);
builder.setPositiveButton(R.string.yes, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
activity.finish();
}
});
builder.setNegativeButton(R.string.no, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With