0

我曾经AsyncTask请求大量数据。收到后,数据在方法内部进行onPostExecute处理。处理数据可能需要一段时间。

根据我的理解,AsyncTask它是异步的并且独立于 UI。

  • 为什么我的活动冻结onPostExecute
  • 如果方法内部的处理时间过长Activity,冻结是否正常?onPostExecute
  • 我怎样才能使它Activity不会冻结onPostExecute
4

4 回答 4

2
  1. 您应该database , network ,parsing在方法中执行所有数据源操作,例如(response.etc)doInBackground
  2. 如果您想更新异步任务中的任何 ui 更新,请使用onProgressUpdate
  3. 我认为您正在执行任何解析操作onPostExecute。尝试parsed datapostexecute.
于 2013-04-24T09:33:26.470 回答
1

为什么我的 Activity 在 PostExecute 上冻结?

根据您的帖子,您对 PostExecute 方法执行了一些耗时的操作。在 PostExecute 上运行在 UI 线程上,所以你的 UI 被冻结没关系。

如果 onPostExecute 方法内部的处理时间过长,Activity 冻结是否正常?

是的,它就是。您应该在 doInBackground 方法中执行长操作(非 UI 线程)

如何使我的 Activity 不会在 PostExecute 上冻结?

尝试将您的长时间操作转移到 doInBackground 方法,并在 PostExecute 中根据响应更新 UI,这是您在 doInBackground 方法中的操作后得到的。

于 2013-04-24T09:33:05.120 回答
0

确保您在doInBackground方法中使用AsynTask方法。

于 2013-04-24T09:32:23.567 回答
0

请参阅 Long Running Task You Need to Bind in doInBackground here you cannot Bind UI control LikeButtonImageView 。在完成后 doInBackgroundonPostExecute 可以 Bind All Require Control ,请确保此处 [ onPostExecute] 您没有运行其他任务。

于 2013-04-24T09:39:39.293 回答