Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace AsyncTask with AsyncTaskLoader #280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yulin2
Copy link

@yulin2 yulin2 commented Feb 22, 2015

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 for reddit-is-fun? Do you want to replace all AsyncTask to AsyncTaskLoader?

@talklittle
Copy link
Owner

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.

@yulin2
Copy link
Author

yulin2 commented Feb 22, 2015

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?

Repository owner deleted a comment from loukia23 Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants