android - 改造同步和异步请求有什么区别?哪个更好,为什么?

标签 android rest retrofit

我真的到处都在搜索这个,我可以同时发出同步和异步数据请求,但我实际上无法理解哪个异步与什么?什么与什么同步?

最佳答案

call.execute() 在当前线程上运行请求。

call.enqueue(callback) 在后台线程上运行请求,并在当前线程上运行回调。

你通常不想在主线程上运行 call.execute() 因为它会崩溃,但你也不想运行 call.enqueue() 在后台线程上。

关于android - 改造同步和异步请求有什么区别?哪个更好,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48151124/

相关文章:

android - 如何使用 CameraX 设置正确的纵横比?

java - 必需的变量,找到的值?

java - 使用 oAuth 2.0 保护基于 Jersey 的 REST 服务

java - 无法设置我的 RecyclerView 以显示来自 API 回调的完整数据

java - Android:如何使用改造从 json 响应中获取特定字符串?

java - 保持应用程序在后台运行

spring - 您可以在 Spring(Boot)之外使用(任何)Spring 的功能吗?

php - Backbone UI 和 CMS 后端 : Wading through the Restful CRUD

java - 错误 : cannot find symbol class Builder (using Retrofit)

Android - Webviewclient onReceivedHttpError 确定是否是主要资源