
这是代码的一部分
public voID onClick(VIEw v) { // Todo auto-generated method stub UserFunctions userFunction = new UserFunctions(); if(userFunction.isNetworkAvailable(getApplicationContext())) { answer=""; for(int check1=0;check1<counter2;check1++){ int check2=0; answer=answer+option4[check1]+"|"; while(check2<counter1){ if(edTxt[check1][check2].getText().toString().equals("")){ answer=""; break; } else{ answer=answer+edTxt[check1][check2].getText().toString()+"|"; } check2++; } if(answer.equals("")){ break; } else{ answer=answer+"||"; } } if(answer.equals("")){ Toast.makeText(this,"Please fill all fIElds",600).show(); } else{ userFunction.form1(surveyID,userID,quesNo,answer); if(total>0){ draw(temp); } else{ ques_no++; ArrayList<nameValuePair> params = new ArrayList<nameValuePair>(); params.add(new BasicnameValuePair("quesNo",Integer.toString(ques_no))); params.add(new BasicnameValuePair("surveyID",surveyID)); count = getJsonFromURL22(surveyCond,params); j=Integer.parseInt(result); if(j==22) { Toast.makeText(this,"Survey Completed",600).show(); Intent home=new Intent(Format16.this,SurveyCompleted.class); UserFunctions userFunctions = new UserFunctions(); userFunctions.full(surveyID); Bundle d=new Bundle(); d.putString("userID",userID); home.putExtras(d); startActivity(home); } public String getJsonFromURL22(String url,List<nameValuePair> params){try{ httpClIEnt httpclIEnt = new DefaulthttpClIEnt(); httpPost httppost = new httpPost(url); httppost.setEntity(new UrlEncodedFormEntity(params)); httpResponse response = httpclIEnt.execute(httppost); httpentity entity = response.getEntity(); is = entity.getContent();}catch(Exception e){ Log.e("log_tag","Error in http connection"+e.toString());}//convert response to stringtry{ BufferedReader reader = new BufferedReader(new inputStreamReader(is,"iso-8859-1"),8); sb = new StringBuilder(); sb.append(reader.readline()); String line="0"; while ((line = reader.readline()) != null) { sb.append(line); } is.close(); result=sb.toString();}catch(Exception e){ Log.e("log_tag","Error converting result "+e.toString());}return result;}解决方法 The application works fine if the internet is fast enough. But as the
speed goes down the application force closes.
它清楚地表明您正在UI Thread上进行网络 *** 作.如果在主线程上执行异步 *** 作,并且如果超过5秒,那么您的应用程序将显示强制关闭对话框,这对于最终用户非常不满意. .
事实上,如果你试图在最新的AndroID版本(即4.0或更高版本)上运行这样的应用程序它将不允许你运行应用程序,它会在检测到在主线程上执行异步 *** 作时立即崩溃.
您必须使用AsyncTask或Handlers来执行长时间运行的应用程序.
浏览以下博客了解更多信息.
http://android-developers.blogspot.in/2010/07/multithreading-for-performance.html
总结以上是内存溢出为你收集整理的android – 慢速互联网连接导致强制关闭全部内容,希望文章能够帮你解决android – 慢速互联网连接导致强制关闭所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)