Can Honeycomb Loaders solve problems with AsyncTask + UI update?

后端 未结 2 655
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-02 00:13

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 some

相关标签:
2条回答
  • 2021-02-02 00:45

    This does not answer your question about Honeycomb loaders but the following link has a pattern that easily handles orientation changes for AsyncTasks.

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

    Theres some other great posts on there as well.

    Update: As OP noted in comments this only works for configuration (orientation) changes, but does not work when using BACK button and restart via Home menu or tasks list.

    If you need one AsyncTask at a time, than you could use a static reference to AsyncTask inside Activity. The other option would be to save the reference to Application.

    Then when a new Activity is started, you look if there is an AsyncTask running and set itself as current Activity (via a setter on AsyncTask). Be sure to synchronize access to Activity inside AsyncTask.

    0 讨论(0)
  • 2021-02-02 00:58

    Yes, from my experience with Loader they seem to solve the common problems people have with AsyncTasks and configuration changes.

    I think Google said that the fragments static library would include Loaders as well so yes, they should work backwards too when the library is released.

    0 讨论(0)
提交回复
热议问题