I have an AsyncTask and a doInBackground method, inside which I send a POST request using Retrofit. My code looks like this:
//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; }
My problem is this: reinstall the send request asynchronously and during its execution the doInBackground method returns a value. Therefore, I need to send the request in the same thread as all the execution in the sequence. One by one. And the return from doInBackground occurs after the request is completed. How to send a request in the same thread using Retrofit?
source share