How to return in retrofit 2 in async query?

Want to return in the asynchronous request I understand that the answer to come later and bring a method but I need to ask him and get an answer immediately or that he would have held the completion of the receiving otnet

function:

public void loadMyMuvi(){
 Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://192.168.0.105:8000")
.addConverterFactory(GsonConverterFactory.create())
.build();
 final MyApiRequestInterface request = retrofit.create(MyApiRequestInterface.class);
 Call<mymuviresponse> call = request.getMyMuvi();
 call.enqueue(new Callback<mymuviresponse>() {

@Override
 public void onResponse(Call<mymuviresponse> call Response<mymuviresponse> response) {
 MyMuviResponse myMuviResponse = response.body();

 if (myMuviResponse.getStatus() == "true") {
 data = new ArrayList<>(Arrays.asList(myMuviResponse.getMyMuvi()));
 } else {
 Log.d(TAG, "no data in request");
}

}

@Override
 public void onFailure(Call<mymuviresponse> call, Throwable t) {
 Log.d("Error", t.getMessage());
}
});
 }</mymuviresponse></mymuviresponse></mymuviresponse></mymuviresponse></mymuviresponse>
July 9th 19 at 11:18
2 answers
July 9th 19 at 11:20
display circle, etc. until you answer.
Response and onfailure or onresponse
Why do something to block? Bad practice.
You can stir up with the events (most likely),but why?
and you can pop more or can make a synchronous request and get what you want ? - Tressie_Nader43 commented on July 9th 19 at 11:23
July 9th 19 at 11:22
@Override
 public Response load(Uri Uri, int networkPolicy) throws IOException {
 final AtomicReference<object> notifier = new AtomicReference<>();
 serverId = "https://" + Utils.API_SERVER_HTTP + "/download/" + serverId;
 fileDownloader = new FileDownloader(serverId, outPath, true, new FileDownloader.IFileDownloaderListener() {
@Override
 public void onProgress(int progress) {
}
@Override
 public void onSuccess() {
 synchronized (notifier) {
 try {
 notifier.set(new Response(decodeBitmap(outPath), false));
 } catch (Exception ex) {
ex.printStackTrace();
 notifier.set(new Exception());
 } finally {
notifier.notify();
}
}
}
@Override
 public void onError() {
 synchronized (notifier) {
 notifier.set(new Exception());
notifier.notify();
}
}
 }, staticHandler);
fileDownloader.execute();
 synchronized (notifier) {
 try {
 while (notifier.get() == null)
notifier.wait();
 } catch (Exception ex) {
ex.printStackTrace();
}
}

 if (notifier.get() instanceof Exception)
{
 throw new ResponseException("File cannot be downloaded", 0, 404);
}
 return (Response) notifier.get();
 }</object>
I do not understand how variable it is , I'm a java newbie - Tressie_Nader43 commented on July 9th 19 at 11:25
A tin plate. So examine the subject,In a stream IG do not need anything Bloch. - Tressie_Nader43 commented on July 9th 19 at 11:28
: nuuu not so gestando, perhaps (as in my example) biocide is not the GUI-thread. - mercedes commented on July 9th 19 at 11:31
tin -I mean the question.
Why not, that depends on what is caused by no or am I wrong? - lilyan.Satterfie commented on July 9th 19 at 11:34
all right, waiting to be the thread from which the method will be called. I had this situation: the application communicated with the server via WebSocket, including uploaded files, but I had to stick this loader (asynchronous) to Picasso, who drew it is also asynchronously, but Picasso hopes that the download will be implemented synchronously, and therefore had to stopit thread until the end of asynchronous loading at the WS and return the bitmap ruturn'ohms. - mercedes commented on July 9th 19 at 11:37
you really need to show some ProgressBar, wait boot and onResponse to process and display uploaded data. - lilyan.Satterfie commented on July 9th 19 at 11:40
: Yes, interesting case. Picasso still alive? Or is it long - lilyan.Satterfie commented on July 9th 19 at 11:43
: quite alive ) - mercedes commented on July 9th 19 at 11:46
and there is still a synchronous call? - lilyan.Satterfie commented on July 9th 19 at 11:49
: well, it was the boot loader is written, the type of built-in (to unasledovala you from something, do not remember). Picasso in or asynctask invokes methods or thread creates. In any case, the instance methods of the loader twitch not in the UI thread and is expected to return bitmap - mercedes commented on July 9th 19 at 11:52
: got it, thanks. - lilyan.Satterfie commented on July 9th 19 at 11:55
Thanks guys ) I decided last night; I this problem by creating simultaneous queries in a separate thread ) but I, as always, there is another problem ) now publish it and I will be glad to see the responses You ) I'm only 3 weeks familiar with java and the android sdk , so please pre-petition if my actions cause fear ) but I can assure you that I learn very quickly ) and how to write this first program is required to Express gratitude to you for aid ) I used to be purely a web programmer in python, php, js, etc vplod ,net but now I want to go into java and object c ) - mercedes commented on July 9th 19 at 11:58
: welcome ) - Tressie_Nader43 commented on July 9th 19 at 12:01
: still do not understand why you started arguing because of Picasso , I use it only at the level when Adapter for rendering elements
@Override
public void onBindViewHolder(DataAdapter.ViewHolder viewHolder, int i) {

viewHolder.tv_name.setText(android.get(i).getNameRU());
viewHolder.tv_rating.setText(android.get(i).getRating());
viewHolder.tv_movie_details.setText(android.get(i).getDescription());

Picasso.with(context).load(android.get(i).getImg()).into(viewHolder.tv_img);
Picasso.with(context).load(android.get(i).getImg()).into(viewHolder.tv_img360);
} - lilyan.Satterfie commented on July 9th 19 at 12:04

Find more questions by tags AndroidJava