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

public interface GeneralCallbacks {
void VolleyResponse(String data);
}

Implement the interface on your activity class

public class YourActivity implements ScoreboardCallback
{
    @Override
    public void VolleyResponse(String data)
    {
      //do stuff with data
    }
}

And finally changing your response function to something like this

        @Override
        public void onResponse(String response) {
            ((GeneralCallbacks)context).VolleyResponse(response); // This will make a callback to activity.
            aPerson.SomeFunction(); // This will call person's function
            Log.d("RESPONSE",response.toString());
        }

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