Skip to content Skip to sidebar Skip to footer

Android Volley Return Value From Response

How do I get the response out of onResponse so that I can return it? I have found this but I don't really understand how to implement it for me. How can I return value from functio

Solution 1:

As it was mentioned, you need to implement interface and get a callback

Create a new interface like this

publicinterfaceGeneralCallbacks {
voidVolleyResponse(String data);
}

Implement the interface on your activity class

publicclassYourActivityimplementsScoreboardCallback
{
    @OverridepublicvoidVolleyResponse(String data)
    {
      //do stuff with data
    }
}

And finally changing your response function to something like this

@OverridepublicvoidonResponse(String response) {
            ((GeneralCallbacks)context).VolleyResponse(response); // This will make a callback to activity.
            aPerson.SomeFunction(); // This will call person's functionLog.d("RESPONSE",response.toString());
        }

Post a Comment for "Android Volley Return Value From Response"