Three quick tips: handling the back button in DialogFragment, chmod permission reference, and the underscore problem in SSL hostnames.

DialogFragment Back Button Handling

DialogFragment has no direct override for the back button. Two approaches were commonly used.

Approach 1: Override in onCreateDialog

1
2
3
4
5
6
7
8
9
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new Dialog(getActivity(), getTheme()){
        @Override
        public void onBackPressed() {
            // Handle back press here
        }
    };
}

Approach 2: Via onKeyListener

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
@Override
public void onResume() {
    super.onResume();
    Dialog dialog = getDialog();
    if (dialog != null) {
        dialog.setOnKeyListener(this);
    }
}

@Override
public void onPause() {
    super.onPause();
    Dialog dialog = getDialog();
    if (dialog != null) {
        dialog.setOnKeyListener(null);
    }
}

Modern Approach: OnBackPressedDispatcher (AndroidX)

For newer versions, use AndroidX’s OnBackPressedDispatcher. Since Fragment 1.6.1, DialogFragment returns a ComponentDialog by default, which has its own OnBackPressedDispatcher:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class MyDialogFragment : DialogFragment() {
    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        return super.onCreateDialog(savedInstanceState).also { dialog ->
            val componentDialog = dialog as ComponentDialog
            componentDialog.onBackPressedDispatcher.addCallback(componentDialog) {
                // Custom back press handling
            }
        }
    }
}

See Android Developer: ComponentDialog and OnBackPressedDispatcher for details.

chmod Permission Reference

Linux file permissions in octal notation:

PermissionValueDescription
---0No permissions
--x1Execute only
-w-2Write only
-wx3Write + execute
r--4Read only
r-x5Read + execute
rw-6Read + write
rwx7Read + write + execute

The three digits represent: Owner / Group / Others.

Common Permission Combinations

1
2
3
4
5
6
sudo chmod 600 file    # Owner read+write only (private key, config)
sudo chmod 644 file    # Owner rw, group+others r (standard file permission)
sudo chmod 700 file    # Owner full access (script, private key)
sudo chmod 755 file    # Owner full, others r+x (executable, directory)
sudo chmod 666 file    # Everyone read+write (rare)
sudo chmod 777 file    # Everyone full access (risky, avoid)

Security advice: Avoid 777. Use 600 for config files, 755 for executables, and 644 for regular files.

The Underscore Problem in SSL Hostnames

Some domains used in our project contained underscores (_), which caused javax.net.ssl.SSLHandshakeException during HTTPS connections — hostnames simply don’t allow underscores.

Specification

Per RFC 952 and RFC 1123, each hostname label may only contain ASCII letters, digits, and hyphens (-). Underscores are not permitted. Affected record types include A, AAAA, MX, and CNAME.

Underscores aren’t completely banned in DNS — RFC 2181 Section 11 allows arbitrary binary content in DNS labels — but hostnames have stricter rules. RFC 2782 deliberately introduced underscore prefixes in SRV records (e.g., _sip._tcp.example.com) to avoid conflicts with hostnames.

Summary

  • Hostnames (URLs, SSL certificates): no underscores allowed
  • SRV records and service discovery: underscores required as prefix
  • Fix: replace _ with - or other compliant characters in domain names

Discussion at StackOverflow: The use of the underscore in host names.

References