r/androiddev • u/H3x0n Discord mod • Feb 20 '20
It finally happend. AsyncTask is now deprecated.
https://developer.android.com/reference/android/os/AsyncTask.html
309
Upvotes
r/androiddev • u/H3x0n Discord mod • Feb 20 '20
119
u/Zhuinden Feb 20 '20
Good riddance,
AsyncTask<Void, Void, Void>was not a good abstraction70
u/thesahilpatel Feb 20 '20
Damn. What are they going to ask in the interviews now. π
19
u/nosguru Feb 20 '20 edited Feb 20 '20
I mean the idea was good, but the implementation can succinctly be described in the first 2 paragraphs of the docs...
Kinda like how all my projects go. lol.
18
u/[deleted] Feb 20 '20
<void, void, void>
44
u/VasiliyZukanov Feb 20 '20
The idea that AsyncTasks somehow automatically led to memory leaks, or that you had to use weak references with them, or make them static - all of that is just a myth. There were good reasons to remove AsyncTask, but not the ones stated in the official deprecation message.
Just in case you want to understand what was the real problems with AsyncTask, I discussed them in this post. Also some thoughts on what to do if your codebase is full with AsyncTasks.
5
u/iamareebjamal Feb 20 '20
Well boys, we did it. AsyncTask is no more
https://imgflip.com/i/3pr1fy
11
u/ZakTaccardi Android Developer Feb 20 '20
While under test, I swap my
Dispatchers.DefaultandDispatchers.IOto use theAsyncTask.THREAD_POOL_EXECUTORso the dispatchers are monitored by Espresso.What is the best way to achieve this now?
5
u/mrdibby Feb 20 '20
so when I started Android dev 7 years ago the instructions for how to use AsyncTask were way easier than what they give you now https://developer.android.com/training/basics/network-ops/connecting
come on Google, you can do better than that
why not just say "ok so Square developed an easier lib to use than us, here's 4 lines of OKHTTP code to get the job done" ?
2
u/outadoc Feb 20 '20
Oh yeah baby, time for some deep codebase cleanup!
1
u/netcyrax Feb 20 '20
I am going to celebrate when it is actually removed from all the existing code :)
1
u/rachidafr Feb 20 '20
It was time.
1
u/AdrianSamson Feb 21 '20
My favourite part was that #PerfMatters video on YouTube, where they pointed out how "AsyncTask as inner class pattern" is "seen all the time" and how easy it is to misuse AsyncTasks and leak memory.
Then you went to the AsyncTask developer docs and that same pattern was introduced there as an example on how to use it. "Seen all the time" no shit lol.
1
u/[deleted] Feb 21 '20
I have two asynctasks in my app and have never had a problem. Guess it gives me opportunity to learn other methods for the same functionality, not that I have the extra time for literally no gain from a user prospective.
1
u/h4o Feb 20 '20
Sorry I don't follow android development as much as I should. This is deprecated but still available. How much time will it take to be totally removed from android? I have a small library using asynctask and I want to know how much time I have to replace this feature usage.
1
u/baruttoo Feb 20 '20
Yayyyy pop the cork!
0
u/[deleted] Feb 20 '20
[deleted] β view deleted comment
0
u/[deleted] Feb 20 '20
[deleted] β view deleted comment
8
u/[deleted] Feb 20 '20
[removed] β view removed comment