gpt4 book ai didi

android - Retrofit execute方法是后台任务

转载 作者:可可西里 更新时间:2023-11-01 17:04:58 25 4
gpt4 key购买 nike

Retrofit .execute 方法是否已经是后台任务,或者我应该在 AsyncTask 中调用此方法在 retrofit 官方文档中它提到回调在 mainThread 中执行,但它不清楚如果执行方法是后台任务。

改造文档:

SYNCHRONOUS VS. ASYNCHRONOUS Call instances can be executed either synchronously or asynchronously. Each instance can only be used once, but calling clone() will create a new instance that can be used.

On Android, callbacks will be executed on the main thread. On the JVM, callbacks will happen on the same thread that executed the HTTP request.

最佳答案

call.execute() //not a background task, works in the foreground(synchronous).
call.enqueue() //This is a background task(asynchronous).

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

关于android - Retrofit execute方法是后台任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50666365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com