admin管理员组文章数量:1418636
I am trying to check if my server is on/off from an Android
application. From my MainActivity
I use this code snippet:
try {
new CheckServer().start();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
This is the class
:
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);
}
}
}
When I run the app, nothing happens(I don't get the message Log
). So after a debugging I discovered that in runtime this part was skipped:
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);
}
}
Can anyone show/tell me why or what I am doing wrong? it will be highly appreciate
本文标签: javaWhy Android heaps over a Thread taskStack Overflow
版权声明:本文标题:java - Why Android heaps over a Thread task? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745296044a2652083.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论