neu*_*t47 9 java android retrofit
我有AsyncTask和doInBackground方法,我在其中使用Retrofit发送POST请求.我的代码看起来像:
//method of AsyncTask
protected Boolean doInBackground(Void... params) {
Retrofit restAdapter = new Retrofit.Builder()
.baseUrl(Constants.ROOT_API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
IConstructSecureAPI service = restAdapter.create(IConstructSecureAPI.class);
//request
Call<JsonElement> result = service.getToken("TestUser", "pass", "password");
result.enqueue(new Callback<JsonElement>() {
@Override
public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
}
@Override
public void onFailure(Call<JsonElement> call, Throwable t) {
}
});
return true;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:异步发送请求并在执行时,doInBackground方法返回值.所以我需要在同一个线程中发送一个请求,即序列中的所有执行.逐一.并且在请求完成后从doInBackground返回.如何使用Retrofit在同一个线程中发送请求?
| 归档时间: |
|
| 查看次数: |
12096 次 |
| 最近记录: |