public inputStream getinputStream() { androidhttpclient clIEnt = androidhttpclient.newInstance(USERAGENT); httpUriRequest request = new httpGet(url); inputStream in = null; try { httpResponse response = clIEnt.execute(request); in = response.getEntity().getContent(); return in; } catch (IOException e) { e.printstacktrace(); } finally { clIEnt.close(); }}
我把这个方法放在Util类中.
但是当在另一个类中调用getinputStream()时,由于androidhttpclient被关闭,我无法获得inputSteam.
如果我没有关闭androidhttpclient,就会出现“发现泄漏,androidhttpclient已创建且从未关闭”.
如何在这种情况下获取内容
public inputStream getinputStream() { androidhttpclient clIEnt = androidhttpclient.newInstance(USERAGENT); httpUriRequest request = new httpGet(url); inputStream in = null; try { httpResponse response = clIEnt.execute(request); return new ByteArrayinputStream(new EntityUtils.toByteArray(response.getEntity())); } catch (IOException e) { e.printstacktrace(); } finally { clIEnt.close(); }}总结
以上是内存溢出为你收集整理的AndroidHttpClient关闭后无法getEntity().getContent()全部内容,希望文章能够帮你解决AndroidHttpClient关闭后无法getEntity().getContent()所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)