HttpResponse response = client.execute(httpPost);在4.0系统中运行异常的问题
来源:互联网 发布:杀手 知乎 编辑:程序博客网 时间:2024/05/18 19:43
最近在做一个项目,涉及到网络通信这块,需要向服务器发送请求,获取服务器端的数据,程序在android 2.2系统中运行正常,在4.0系统中运行获取不到数据。
网上查了下资料,发现 Android在4.0之前的版本 支持在主线程中访问网络,但是在4.0以后对这部分程序进行了优化,访问网络的代码不能写在主线程中了。
解决方法如下:
在OnCreate()中加入如下代码:
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() // or .detectAll() for all detectable problems .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build());</span>
问题就解决了,StrictMode方法仅在4.0系统中使用,因此需使用4.0以上的系统。
0 0
- HttpResponse response = client.execute(httpPost);在4.0系统中运行异常的问题
- httpclient HttpResponse response = client.execute(post);报空指针问题
- 如何解决httpResponse = httpClient.execute(httpGet);无法执行的问题?
- Android 中//此句无响应 HttpResponse httpResponse = httpClient.execute(post);
- ASP.NET中httpResponse与Response
- HttpClient get请求在HttpResponse中无法获得Location的问题
- HttpClient get请求在HttpResponse中无法获得Location的问题
- HttpClient get请求在HttpResponse中无法获得Location的问题
- HtmlParser基础教程 - 在java中解析获取的HttpResponse
- HtmlParser基础教程 - 在java中解析获取的HttpResponse
- 关于在Response Header中取不到的问题
- HttpResponse httpResponse=null;
- WebView运行在系统进程的问题
- 关于用.net系统在运行时出现的异常
- Android WebView 运行在系统进程引发的异常
- 问题:在运行android的项目时出现的异常
- 在Vista的IIS系统中运行ASP的几个配置问题
- 可运行的JAR文件,如何在系统中运行
- 人脸识别之特征脸方法(Eigenface)PCA方法
- PAT (Advanced Level) 1055. The World's Richest (25) 年龄区间内最有钱的人,结构体排序
- zookeeper使用场景
- 1614 - Hell on the Markets(贪心)
- 中国象棋机器人
- HttpResponse response = client.execute(httpPost);在4.0系统中运行异常的问题
- 工作3个月后个人对测绘专业的重新反思(重新思考武大测绘学科就业问题和读研问题)
- AM335x(TQ335x)学习笔记——触摸屏驱动编写
- ${pageContext.request.contextPath}和request.contextPath的区别 分类: jsp el表达式 2013-07-17 15:50 7184人阅读 评论
- svn---安装、启动、关闭
- 【Unity3D游戏开发】Time.timeScale=0暂停游戏的情况下播放动画 (七)
- Android Studio手动导入第三方类库
- EALayout 第四节 引用另一个控件的位置属性
- POJ 2566 Bound Found(前缀和排序 + 尺取法)