English 中文(简体)
Can Honeycomb Loaders解决AsyncTask + UI更新的问题?
原标题:Can Honeycomb Loaders solve problems with AsyncTask + UI update?

Doing something in background and then updating UI is very hard to implement correctly in Android. It s simply badly designed. Typical example is an AsyncTask that fetches something from the web and displays the result. There are 2 problems with this:

  1. AsyncTask提到活动(因为需要更新其调查数据)。 在筛选方向改变后,活动重新开始。 但是,AsyncTask仍然提到旧的被毁活动,因此它可以更新新的活动倡议。

  2. 这可能会导致外围。 想象一下,你们的活动有许多比图,并开始一些阿辛卡克。 你的BACK报(活动已完成)但AsyncTask仍在运行,因为提到了活动,所以带有图象的活动仍然记忆中。 为此(启动活动和BACK),你很快或更晚地有一支部队。

这个问题是可以解决的,但情况过于复杂。 在一项活动中,我有3个不同的AsyncTasks,其中每一个可以同时进行。 正确执行这一点令人沮丧。 守则实际上难以理解和辩论。

rel=“nofollow”>Honeycomb Loaders, 在一定程度上解决这一问题? 是否有办法在Honeycomb Anders版本中使用吗?

最佳回答

是的,从我对<代码>Loader的经验来看,这些经验似乎解决了人们在<条码>上遇到的共同问题。

我认为,谷歌说,碎块的静态图书馆将包括Loaders,如果是的话,它们也应该在图书馆放行时落后。

问题回答

这并不能回答你关于Honeycomb装载器的问题,但以下链接具有便于处理AsyncTasks方向变化的模式。

http://evancharlton.com/thoughts/rotating-async-tasks/

Theres some other great posts on there as well.

<>Update: 正如在评论中指出的,这只是为了组合(方向)的改变而努力的,但在使用BACKhton和通过重新启动时并不奏效。 家庭菜单或任务清单。

如果你需要一名AsyncTask,那么你可以静态地提及AsyncTask内部活动。 另一种选择是避免提及申请。

然后,当开始新的活动时,请看AyncTask是否运行,并把它当作当前活动(通过AsyncTask的一组活动)。 保证在AsyncTask地区同步开展活动。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签