Android 启动时HTTP请求期间IOException_已完成

Android 启动时HTTP请求期间IOException_已完成,android,httpclient,boot,Android,Httpclient,Boot,我有一个Android应用程序,它有这样一个语句,将数据发布到服务器 HttpResponse httpresponse = httpclient.execute(httppost); 当我启动应用程序时,该语句执行良好。我已经使我的应用程序在启动后自动启动。当它启动时,我在这一行收到一个IOEXCeption,其中包含消息my hostname。主机一直在运行,因为当我手动启动应用程序时,相同的语句工作正常。此问题仅在手机启动时发生 以前有人遇到过这个问题吗 CommansWare, 我在

我有一个Android应用程序,它有这样一个语句,将数据发布到服务器

HttpResponse httpresponse = httpclient.execute(httppost);
当我启动应用程序时,该语句执行良好。我已经使我的应用程序在启动后自动启动。当它启动时,我在这一行收到一个IOEXCeption,其中包含消息my hostname。主机一直在运行,因为当我手动启动应用程序时,相同的语句工作正常。此问题仅在手机启动时发生

以前有人遇到过这个问题吗


CommansWare, 我在onReceive调用中使用了这个新方法来检查网络连接。这样我的问题就解决了,这意味着它发布了“in boot Completed”消息并继续成功地执行http请求,但它看起来并没有退出,而“not online”消息则无休止地显示出来。怎么会这样?这不是正确的解决方案吗

public void onReceive(Context context, Intent intent) 
        {
            while(!isOnline(context) )
            {
                Toast toast = Toast.makeText(context, "Not online", Toast.LENGTH_SHORT);
                toast.show();   
            }

                Toast toast = Toast.makeText(context, "in boot completed", Toast.LENGTH_SHORT);
                toast.show();

            }
        }

        protected boolean isOnline(Context context) {

            ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);    
            NetworkInfo netInfo = cm.getActiveNetworkInfo();
            if (netInfo != null && netInfo.isConnected())
            {
                Toast toast = Toast.makeText(context, "returned true", Toast.LENGTH_SHORT);
                toast.show();
                return true;        
            } 
            else 
            {
                Toast toast = Toast.makeText(context, "returned false", Toast.LENGTH_SHORT);
                toast.show();
                return false;
            }
        }

此时可能没有活动的Internet连接。毕竟,该设备只是从关闭状态开始启动。这与任何其他操作系统都没有区别

您可能需要做一些事情来延迟HTTP操作,直到Internet连接可用为止。例如,您的
BOOT_COMPLETED
接收器可以使用
AlarmManager
set()
来安排在几分钟内再次获得控制权,届时设备有望变得更稳定。当然,您还需要使用
ConnectivityManager
来确定当时是否存在Internet连接,并且您可能更愿意做一些复杂的接收器工作来收听
ConnectivityManager
广播,可能比使用
AlarmManager
路由更快地完成HTTP工作