Код: Выделить всё
try {
new CheckServer().start();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Код: Выделить всё
public class CheckServer extends Thread {
URL url = new URL("server-address");
public CheckServer() throws MalformedURLException {
}
@Override
public void run() {
try
{
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
int code = urlConnection.getResponseCode();
Log.d("test", "test connection > " + code);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Код: Выделить всё
public void run() {
try
{
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
int code = urlConnection.getResponseCode();
Log.d("test", "test connection > " + code);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... hread-task
Мобильная версия