Android 中的异步任务

发布于 2024-09-27 02:29:12 字数 257 浏览 2 评论 0原文

任何人都可以告诉有关 android 应用程序中使用的“asynctask”吗?目前我正在开发一个应用程序,在该应用程序中我必须创建一个类,在该类中我必须获取给定的任何特定 URL 的响应。

在这个特定的课程中,我被告知要使用“asynctask”来执行此任务。到目前为止,我的所有问题都得到了非常快速的答复,我非常感谢自从我在这里发布第一个问题以来所有帮助我的人。

我对 Android 编程相当陌生,并且对社区对我的伪装感到有点信心。

谢谢, 大卫

Can anybody tell about the "asynctask" used in android application. Currently I am working on an application where I have to create a Class in which I have to just get the response of any particular URL given.

I this particular class I was told to perform this task by making use of "asynctask". I had been getting very quick responses of all my Questions from here so far and I am greatly obliged to all of them who are helping me since my first question I posted here.

I am quite new to Android Programming and feeling a bit confidence by the community's camouflage with me.

Thanks,
david

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

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

发布评论

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

评论(1

装纯掩盖桑 2024-10-04 02:29:12

Google 的 AsyncTask 文档非常出色:http:// developer.android.com/reference/android/os/AsyncTask.html

它基本上是一个使线程变得非常简单的构造。当您执行诸如向某个 URL 发出 Web 请求之类的操作时,您不希望阻塞 UI 线程。但是,您通常希望在后台任务完成后用结果更新 UI。

AsyncTask 让这变得简单。首先,您需要创建一个扩展 AsyncTask 的类。当您执行任务时,将在后台线程上调用其doInBackground方法。您可以在此处从网络下载某些内容或执行任何其他您需要执行的操作。

doInBackground 的返回值将提供给 onPostExecute 方法,该方法可以适当地更新 UI。

再次,我建议您查看 Google 的文档。他们有关于如何使用它的很好的例子。

Google's documentation for AsyncTask is pretty excellent: http://developer.android.com/reference/android/os/AsyncTask.html

It's basically a construct that makes threading very simple. When you are doing something like making a web request to some URL, you don't want to block the UI thread. However, you usually want to update your UI with the results once your background task has completed.

AsyncTask makes this easy. First, you need to create a class that extends AsyncTask. When you execute the task, its doInBackground method will be called on a background thread. This is where you can download something from the Web or do whatever else you need to do.

The return value from doInBackgroundwill be provided to the onPostExecute method, which can update the UI appropriately.

Again, I recommend checking out Google's documentation. They've got great examples on how to use this.

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