Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volley 1.2.0 listener calls multiple times #409

Closed
VirajShirwalkar opened this issue Apr 17, 2021 · 3 comments
Closed

Volley 1.2.0 listener calls multiple times #409

VirajShirwalkar opened this issue Apr 17, 2021 · 3 comments

Comments

@VirajShirwalkar
Copy link

I used volley 1.2.0 and found that for one get api call, there is a listener which gets called multiple time and dont know why.

 requestQueue.addRequestEventListener((request, event) -> {
    Log.i(TAG, "----- addRequestEventListener -----");
   if (request.hasHadResponseDelivered() && event == RequestQueue.RequestEvent.REQUEST_FINISHED){
       // do your work here...
   }
});

please help me to clear this.
(BTW i dont remove that listener anywhere in my code. So adding same listener multiple times may create problems.
image
NetworkGetCall is just a class to call volley get method.
)

@jpd236
Copy link
Collaborator

jpd236 commented Apr 18, 2021

RequestEventListener is for listening to various events over the course of executing a request. It's intended for debugging/logging purposes rather than meant to be what you actually use to listen to responses for a particular API call.

Why are you using this interface, as opposed to passing in a listener to the Request constructor (which would only be invoked once - unless the request is using soft caching)?

@VirajShirwalkar
Copy link
Author

Thank you for the reply. But I am not satisfied with the answer. There is no proper or simple example of this version library (1.2.0) available anywhere to understand what are the changes and how to use them.
There are two places where response gets received. like below,

StringRequest stringRequest = new StringRequest(apiUrl, response -> {  

and

@Override
protected void deliverResponse(String response) {
   super.deliverResponse(response);
}

Now, where to collect the response?
where to finish the final process to navigate back to Activity / Fragment?
Please help.

@jpd236
Copy link
Collaborator

jpd236 commented Apr 19, 2021

There is documentation and a simple example of how to make requests at https://developer.android.com/training/volley. Nothing significant has changed in version 1.2.0 regarding how to use the library for basic requests compared to older versions.

The first callback you mentioned is the one provided by the code making the request. That would typically be where you'd act on the results, or pass the results to an interested Activity/Fragment.

The second is only needed when you're implementing a custom subclass of Request - see https://developer.android.com/training/volley/request-custom#deliverresponse.

I'm going ahead and closing this out as this seems more like a question of how to use the library than an issue report. If you have further questions about how to use the library, I'd recommend using a general help forum like our user group at volley-users@googlegroups.com, or a site like StackOverflow. We do have an open bug (#395) to flesh out the docs a bit further and hopefully make them more useful.

@jpd236 jpd236 closed this as completed Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants