Android Internet连接崩溃
在连接html网站并使用该代码解析某些信息之前,我的应用程序会进行连接检查:Android Internet连接崩溃,android,http,connection,network-state,Android,Http,Connection,Network State,在连接html网站并使用该代码解析某些信息之前,我的应用程序会进行连接检查: public boolean NetworkInfo(Context context) { // Netzwerk Infos anzeigen if (context != null) { ConnectivityManager mgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SER
public boolean NetworkInfo(Context context) {
// Netzwerk Infos anzeigen
if (context != null) {
ConnectivityManager mgr = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (mgr != null) {
boolean mobileNetwork = false;
boolean wifiNetwork = false;
NetworkInfo mobileInfo = mgr
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifiInfo = mgr
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mobileInfo != null)
mobileNetwork = mobileInfo.isConnected();
if (wifiInfo != null)
wifiNetwork = wifiInfo.isConnected();
return (mobileNetwork || wifiNetwork);
}
}
return false;
}
但在连接过程中,互联网状态可能会发生变化,应用程序不会收到所有请求的信息
如何防止应用程序因数据丢失而崩溃?在线程运行的整个过程中,是否有什么东西可以检查连接?在使用数据之前测试数据。崩溃产生了一些logcat输出?由于解析器无法转发所需的信息,因此存在nullpointer或java.lang.RuntimeException错误。要添加if语句来检查数据,似乎是一个很好的解决方案。。。