r/android_devs • u/AD-LB • Sep 29 '21
Discussion Google still uses the deprecated AsyncTask even in new code
Check the code of CacheClearingActivity (used to show a dialog to clear cache, and clears the cache), which can be used only from API 30 (Android 11 ) :
Not only that, but it has non-cancellable AlertDialog (and instead of DialogFragment), and the AsyncTask holds a reference to the Activity and the dialog...
Not to mention it doesn't save its state, so, suppose it's in the middle of clearing the cache, and you change the orientation, it will ask you again about clearing the cache...
I know that it's a part of the OS so they are more limited, but AsyncTask and Dialog have better alternative there, and saving the state is something that's available since the beginning... Even when using an AsyncTask, there are better ways to handle it.
And a non-cancellable dialog isn't a nice UX, and is against all that exists on Android OS.
11
u/Evakotius Sep 29 '21
If you check the commit history for the file you will see that the first guy firstly did it without async task, another guy modified it a bit, then the first guy decided to add the async task.
7
u/Traditional_Ad_8775 Sep 30 '21
It's fine as long as he can invert a binary tree.
16
u/ComfortablyBalanced You will pry XML views from my cold dead hands Sep 29 '21
Deprecated is just a suggestion! /s
8
u/iamafraidicantdothat Sep 30 '21
I'm not surprised. G does not hire experienced Android developers, they hire engineers which can solve algorithm problems.
6
u/VasiliyZukanov Sep 30 '21
I learned not to expect much from Google's code, but this still surprises me. It's like someone built a time machine and asked a newbiew developer from 2010 to implement this feature.
5
u/gilmore606 Sep 30 '21
thought this was /r/mAndroidDev
4
u/[deleted] Sep 29 '21
Old habits die hard.
4
u/AsdefGhjkl Sep 30 '21
I saw this mentioned before, but might there really be some correlation between nonsensical interview requirements (maths, algorithms and data structures) and inability to have some basic architectural sense?
And also, one thing is looking at this code, which is simple and likely works just fine. Another thing is what all of us experience daily in tools, apps, OSes that break all the time and get broken with every new release, which are probably all horrible over-engineered, badly-engineered codebases.
2
u/campid0ctor Oct 01 '21
I wonder what would Android SDK code look like if they used the latest Java, I feel like it would improve a lot
0
u/houseband23 Sep 30 '21
Don't they have RxJava? I remember seeing that in WorkManager though...