D
D
Dima Sokolov2018-10-06 12:09:56
Java
Dima Sokolov, 2018-10-06 12:09:56

Choosing a multithreading solution in Android?

I learned from one course that using Thread and ASyncTask causes a memory leak and you need to use rxJava.
What other pros/cons are there? What about kotlin coroutines?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AndroidM, 2018-10-06
@AndroidM

ASyncTask, as far as I know, queues the execution of tasks, so ASyncTask is not suitable for too long. While there is a method to run tasks in parallel, I wouldn't use it at all.
Memory leaks are specifically caused not by Thread and ASyncTask, but not by the correct work with objects. In addition, you can use weak references weakreference - which will allow you to remove an object from memory without considering this reference.
If you choose from Thread and ASyncTask - then I tend to Thread.
rxJava is just a library, besides, if you work with references (objects) incorrectly, a memory leak is also possible.
PS I'm a newbie like you so I could be wrong.

E
Eugene, 2019-01-23
@evgdev

I think it's better to use Coroutines, because they eat less memory, judging by the reports, and a convenient async, await mechanism.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question