Different types of request using volley-library in an android with easy explanation

In this tutorial,we will learn about the types of request using  volley-library in an android step by step.

If you want to learn more about the volley-library then visit our precious tutorial https://placementpreparation.com/2019/10/05/volley-singleton-pattern-in-android-with-easy-explanation/

Types of request using volley-library in an android

1.String Request

2.JSONObject Request

3.JSONArray Request

4. Image Request

1.String Request


String url=”https://your_json_url”;
StringRequest stringrequest=new StringRequest(Request.Method,GET,url,new Response.Listener<String>( )
{
@Override
Public void onResponse(String response)
{
}

},
new Response.ErrorListener( )
{
@Override
Public void onErrorResponse(VolleyError error)
{
}
});

requestqueue.add(stringrequest);

2.JSONObject Request

String url=”https://your_json_url”;
JsonObjectRequest jsonobjectrequest=new JsonObjectRequest(Request.Method,GET,url,new Response.Listener<JSONObject>( )
{
@Override
Public void onResponse(JSONObject response)
{
}

},
new Response.ErrorListener( )
{
@Override
Public void onErrorResponse(VolleyError error)
{
}
});

requestqueue.add(jsonobjectrequest);

3.JSONArray Request

String url=”https://your_json_url”;
JsonArrayRequest jsonarrayrequest=new JsonArrayRequest(Request.Method,GET,url,new Response.Listener<JSONArray>( )
{
@Override
Public void onResponse(JSONArray response)
{
}

},
new Response.ErrorListener( )
{
@Override
Public void onErrorResponse(VolleyError error)
{
}
});

requestqueue.add(jsonarrayrequest)


4.Image Request


String url=”https://your_json_image.png”;
ImageRequest imagerequest=new ImageRequest(Request.Method,GET,url,new Response.Listener<Bitmap>( )
{
@Override
Public void onResponse(Bitmap response)
{
}

},
new Response.ErrorListener( )
{
@Override
Public void onErrorResponse(VolleyError error)
{
}
});

requestqueue.add(imagerequest);

Hope,i explained all the topics very well manner step by step if you have any query then you can comment me.

sumankumar80

Hello Friends,I have written and developed this website because you can learn technology easily ,prepare for the placement and also for the any type of examination . By :Suman Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *