Prevent Android alert dialog from closing on outside touch

Posted by dogukanhan on February 06, 2020 · 1 min read
Dialog dialog =    new AlertDialog.Builder(this)
                    .setTitle("Connection Failed")
                    .setMessage("Tying to connect server, please check your network.")
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .create();
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();