在 Android 中保持 HttpClient 的活动
我正在开发一个 Android 应用程序,它从有状态的网络服务器获取数据。因此,维持了一个 httpssession。
目前我已经在我的 android-app 中开发了一个单例类,它负责与网络服务器的所有通信。
我担心的是,如果没有对该类(我的 httpclient)的有效引用,垃圾收集器可能会标记 &席卷了这个班级,从而杀死了会议。
有什么办法可以让这个班级继续存在下去吗? android 中是否有类似于 ServletContext 或 HttpSession 的东西,我们可以在其中保留 httpclient 的引用?
I am developing an android application which fetches data from a stateful web-server. Hence a httpsession is maintained.
Currently I have developed a singleton class in my android-app which is responsible for all the communication with the web-server.
My concern is that if there is no valid reference to this class (my httpclient) than the garbage collector may mark & sweep this class hence killing the session.
Is there any way I can keep this class alive? Do we have somthing similar to ServletContext or HttpSession in android where we can keep the reference of my httpclient?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 Android Services 或 AsyncTask 中四处寻找“HttpClient”的解决方案...
几个链接:
不使用 HTTPCLIENT,但很高兴了解服务。
HttpClient 作为后台服务...
还有这个伙计们说“keep-alive”在手机上不起作用?其实没试过...
You can look around for solutions with "HttpClient" inside Android Services or AsyncTask...
A couple of links:
Not with HTTPCLIENT, but nice to get to know Services.
HttpClient as Background Service...
And this guys says "keep-alive" does not work on mobiles? Havent tried it, actually...