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
| |
Approach 2: Via onKeyListener
| |
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:
| |
See Android Developer: ComponentDialog and OnBackPressedDispatcher for details.
chmod Permission Reference
Linux file permissions in octal notation:
| Permission | Value | Description |
|---|---|---|
--- | 0 | No permissions |
--x | 1 | Execute only |
-w- | 2 | Write only |
-wx | 3 | Write + execute |
r-- | 4 | Read only |
r-x | 5 | Read + execute |
rw- | 6 | Read + write |
rwx | 7 | Read + write + execute |
The three digits represent: Owner / Group / Others.
Common Permission Combinations
| |
Security advice: Avoid
777. Use600for config files,755for executables, and644for 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
- Android Developer: ComponentDialog
- Android Developer: OnBackPressedDispatcher
- RFC 952 - Hostname Specifications
- RFC 1123 - Hostname Requirements
- RFC 2181 Section 11 - DNS Name Syntax
- RFC 2782 - SRV Record Specification
- StackOverflow: The use of the underscore in host names
- Wikipedia: Hostname - Restrictions