Open yulin2 opened 9 years ago
Yes, AsyncTaskLoader
is better when working with Fragments. These days I prefer the Loader framework over AsyncTask
whenever possible.
However, the most recent fad is RxJava. Since you are doing research, you should look into how Loaders compare with Reactive event processing. Some people eschew Loaders (and even Fragments) entirely, in favor of simpler mechanisms.
Yes, RxAndroid(or RxJava) supports emit multiple values and it provides better way to issue exceptions.
However, from my knowledge to Rx, you still need to handle its lifecycle manually to avoid memory leak (for example, unsubscribe all Observers
in onDestroy
). Also, RxAndroid doesn't prevent losing task result. This drawback is similar to AsyncTask.
For Loader
, its lifecycle is handled by Android system automatically to avoid memory leak, and it caches the task result so the task needn't to be executed repeatedly if there's an orientation change. From this point of view, I think AsyncTaskLoader
is better. What do you think?
Hello, I'm doing research on Android async programming. Some articles (for example this article) mention that AsyncTask leads to memory leak and losing task result when there's a configuration change (such as orientation change). Android docs recommend AsyncTaskLoader (require API level 11), which avoid the problems in AsyncTask.
I try to replace one AsyncTask with AsyncTaskLoader in
reddit-is-fun
in this pr (you don't have to merge). Do you think AsyncTaskLoader will work better forreddit-is-fun
? Do you want to replace all AsyncTask to AsyncTaskLoader?