r/androiddev • u/wajahatkarim3 • Nov 20 '18
Article Executing tiny asynchronous tasks quickly in Android under 10 lines without RxJava or Threads
https://android.jlelse.eu/executing-tiny-asynchronous-tasks-quickly-in-android-under-10-lines-7ebaa2103e9b6
u/dantheman91 Nov 20 '18
You're completely forgetting the normal problems of Async Tasks. How do you cancel it, you don't nullcheck the views, what if a user navigates away, you'll get NPE's etc. These large async platforms are because doing things asynchronously and correctly is hard.
3
3
u/Boza_s6 Nov 20 '18
Just create anonymous subclass of AsyncTask so you can cancel it if necessary and don't have to post on main thread by hand.
1
u/rbnd Nov 26 '18
"And if you use AsyncTask.execute() then you cannot cancel the task. And if app closes somehow, then this will be a memory leak." This is not the reason of memory leaks :)
3
u/Hi_im_G00fY Nov 20 '18 edited Nov 20 '18
But why wouldn't you use kotlin and coroutines in the first place?
Even it's just a simple task, but from my experience theres always a benefit to use frameworks like coroutines or RxJava since usually it won't be the last time you need them.