Android tabhost 与异步 HttpClient

发布于 2024-12-07 19:34:46 字数 391 浏览 0 评论 0原文

我有一个带有选项卡的应用程序,每个选项卡都有 HttpCLient,每次用户单击选项卡时都会触发 HttpCLient,并在 tabActivity 线程中下载页面。当用户点击一个选项卡然后切换到另一个选项卡时,他必须等待几秒钟,以便将请求发送到服务器并收到回复。我想使选项卡之间的切换与 HttpClient 异步。即使我将请求放入线程中它也不起作用,甚至当我在每个选项卡上引入 TabGroupActivity 时它也不起作用。 我有一个单独的类,其中包含对服务器的所有请求。我应该用 asyncTask 扩展这个类吗? (这实际上是我一直在考虑的最后一件事可能有帮助)


编辑: 在每个选项卡上 onPause 我都在执行 Thread.join() nad 似乎该操作会减慢返回同一选项卡的所有过程

I have an application with tabs and every tab has HttpCLient that is triggered every time user clicks on the tab and a page is downloaded in a tabActivity thread. When user clicks on tab and then switches to another one, he must wait for a few seconds, so that the request will be sent to server and reply received. I want to make switching between the tabs asynchronous from the HttpClients. It did not work even when i put requests in threads and it even did not work when I introduced TabGroupActivity on every tab.
I have a separate class with all the requests to the server. SHould i extend this class with asyncTask? (This is actually the last thing i have been thinking about that could help)


EDIT:
On every tab onPause i am doing Thread.join() nad it seems that it is the action that slows down all the process of comming back to the same tab

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摇划花蜜的午后 2024-12-14 19:34:46

为了防止 UI 阻塞,所有可能运行缓慢的操作(例如网络)都应该在后台运行,例如通过某种并发方式(例如 Asynctask)。

我认为 Asynctask 是更好的选择(与线程相比),因为它将所有内容封装到一个类中,并且是原生 android。 (例如,使用此类时不需要使用 RunOnUIThread)

阅读本文以获取更多信息:http://www.vogella.de/articles/AndroidPerformance/article.html

to prevent UI from blocking, all potentially slow running operations (such as networking) should run in the background, e.g. via some way of concurrency such as Asynctask.

I think Asynctask is better choice (comparing with threading) because it encapsulate everything into a single class, and is native android. (e.g. you don't need to use RunOnUIThread when using this class)

read this article for more information: http://www.vogella.de/articles/AndroidPerformance/article.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文