Is there a good way to avoid the "host is not resolved" error that crashes an app? Some sort of a way to try connecting to a host ( like a URL ) and see if it's even valid?
Wrap the operation in a try/catch. There are many ways that a URL can be well-formed but not retrievable. In addition, tests like seeing if the hostname exists doesn't guarantee anything because the host might become unreachable just after the check. Basically, no amount of pre-checking can guarantee that the retrieval won't fail and throw an exception, so you better plan to handle the exceptions.
In my case Patterns.WEB_URL.matcher(url).matches() does not work correctly in the case when I type String similar to "first.secondword"(My app checks user input). This method returns true.
URLUtil.isValidUrl(url) works correctly for me. Maybe it would be useful to someone else
This is the correct sollution that I'm using. Adding https:// before original text prevents text like "www.cats.com" to be considered as URL. If new URL() succeed, then if you just check the pattern to exclude simple texts like "https://cats" to be considered URL.