Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
No. Asnyc tasks are problematical for certain usecases, and can lead to memory leaks if not used correctly. you can use the Loader pattern, or a background thread/events.
Also, never do IO on the main thread. Never. Turn on the strict mode to elimate those. -
Mb3leb21497y@magicMirror can you please tell me more abou memory leaks in async task? Because am still not sure if i have to do my calls in async task or on the main thread am still doing my research concerning it
-
rakesh1327yI prefer Okhttp3 for Web service calls.
No need to worry about async task/any loder.
- Use async method of Okhttp
- Its good to implement interface to handle result callbacks -
@Mba3gar Never do IO on the Main thread. Never. I cannot stress this enough: Only really really bad devs do IO on the Main thread.
@rakesh OkHttp vs AysncTask...
same as asking how do you prefer to use a car, some say they use a cabriole, some say racecar, other say a hutchback. But there is is only one who says he uses a v8 engine, and everyone looks at them... -
Mb3leb21497y@magicMirror so from now on i will always use async task for my http calls. Thank you
-
Its not 'prefer', if you do api calls on the main thread, i will personally punch you. Use okhttp or volley or retrofit or whatever.
-
rakesh1327y@magicMirror
If I didn't understand you wrong. It wasn't about Async vs Okhttp3
Main problem: Json calls, best practice
Solution A: MUST use background thread for HTTP calls
Solution B: SHOULD use okhttp3, as It includes calling a web call and background handling both.
Im with you on " Never do IO on the Main thread" . -
gvnix19227yWell don't do anything intensive on the UI thread.
I have used asynctask for all of the webservice calls. I did however make a small framework for myself to make it easier. -
Mb3leb21497yBut guys when i already oost this question of stackoverflow they already said that retrofit does never do any calls on the main UI thread by default
-
creator20157yRetrofit is a good way, however Android docs recommends using Intent services instead. They are good, if the download size are big.
I prefer to use AsyncTasks within a singleton class. I have tested this pattern multiple times and I rarely get any Memory leaks.
Here's few good reads
https://stackoverflow.com/q/...
https://marsic.info/2016/03/...
“Using IntentService vs AsyncTask in Android” @KevinHoffman https://android.jlelse.eu/using-int...
Also try to follow advice of Commonsware guy on Stackoverflow. He's the top Android developer there by reputation and almost always give you a good advice on anything related to Android. Romanguy is another example. -
You can try ReactiveX instead, much better than AsyncTasks https://github.com/ReactiveX/RxJava
-
@Mba3gar yes, it's ReactiveXJava
ReactiveX has different iterations for different languages
Related Rants
@Android Question
Does all android devs use Async Task for their Json calls or you prefer to do them on Main Thread ?
Am just asking to improve my skills and get some senior programmers opinion
rant
android
json
call
http requests