Everywhere it is written that RxJava (+ RxAndroid) is better than AsyncTask, and what are the real advantages of RxJava (+ RxAndroid) over AsyncTask?

  • It also interests me) - elik
  • one
    Instead of noodles from kolbekov, etc. beautiful chains from calls of asynchronous methods. - Suvitruf

1 answer 1

RxJava is mainly used if you have a lot of tasks, you can put them in a sequence that you know when you're done, and the next one is about to begin (you can conveniently manage this stack of threads if necessary). And use AsyncTask if you have more than one launch, since you have no guarantee of what task will be performed first, and this can alternate many errors. If you care about order, RxJava allows you to make consecutive calls.

As for memory leaks, we can have AsyncTask as an internal activity class. Now, since it is associated with activity, when an action is destroyed, the context is still hanging around and will not be collected by garbage, this is part of a memory leak.

This is where RxJava can help. if any errors occur at all, we can call onError subscribers and do the actions we need. So if one task comes down and Async goes a lot towards Rx.

  • It would be better with examples. - Suvitruf
  • one
    Not convinced. Are AsynTask'i not executed consistently? What does it mean to know when the task will end? AsynTask can also handle errors. - AleksanderSh
  • @elik, and if in the same activation you do not unsubscribe the subscriber, there will be no leakage? - Yura Shinkarev