{"id":573,"date":"2017-11-06T05:49:30","date_gmt":"2017-11-06T05:49:30","guid":{"rendered":"http:\/\/abhiandroid.com\/programming\/?page_id=573"},"modified":"2019-06-14T12:05:59","modified_gmt":"2019-06-14T12:05:59","slug":"volley","status":"publish","type":"page","link":"https:\/\/abhiandroid.com\/programming\/volley","title":{"rendered":"Volley Tutorial With Example In Android Studio"},"content":{"rendered":"<p>Volley is a HTTP library developed by Google and was first introduced during Google I\/O 2013. This library is used to transmit data over the network. It actually makes networking faster and easier for Apps. It is available through AOSP(Android Open Source Project) repository.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-789\" src=\"\/programming\/wp-content\/uploads\/2017\/11\/Volley-Example-Android.gif\" alt=\"Volley Example Android\" width=\"167\" height=\"257\" \/><\/p>\n<p>The volley library has the features like automatic scheduling of network request, multiple concurrent connections, request prioritization, cancel\/block a request, easier management of UI with data fetched asynchronously from the network and also offers easier customization.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important Note:<\/strong><\/span> Volley uses cache to improve the App performance by saving memory and bandwidth of remote server.<\/p>\n<hr \/>\n<h4><strong>Volley Uses Caches To Improve Performance In Android:<\/strong><\/h4>\n<p>Volley uses caches concept to improve the performance of App. For example, lets say you are using Asynctask to fetch image and description from a JSON array created in server API. The content is fetched in the portrait mode and now user rotate screen to change it to landscape mode. The activity is destroyed and so the content will be fetched again. Since the user is calling the same resource again to server so it is a waste of resource and ultimately a poor user experience.<\/p>\n<p>Volley provide solution to this problem as it caches the data. When user request the same data, instead of calling from server Volley directly shows it from cache saving resource and thus improving user experience.<\/p>\n<p><strong>Below is the basic diagram of Volley:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-765\" src=\"\/programming\/wp-content\/uploads\/2017\/11\/Volley-In-Android.png\" alt=\"Volley-In-Android\" width=\"523\" height=\"362\" srcset=\"https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-In-Android.png 523w, https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-In-Android-300x208.png 300w\" sizes=\"auto, (max-width: 523px) 100vw, 523px\" \/><\/p>\n<hr \/>\n<h4><strong>Understanding RequestQueue &amp; Working With Volley In Android:<\/strong><\/h4>\n<p>Volley is a networking library managed by the RequestQueue and mainly used for smaller Networking purposes in Android. To use it, first you need to instantiate the RequestQueue and later on you can start or stop request, add or cancel request and access the response cache(s).<\/p>\n<pre>RequestQueue queue = Volley.newRequestQueue(this);<\/pre>\n<p>After instantiating\u00a0RequestQueue, a request must be created. The default request classes already included in Volley library are String request, JSON request, and image request. You can also create custom request by\u00a0extending Volley\u2019s request class.<\/p>\n<p><strong>Request Constructors used in Volley takes 4 parameter:<\/strong><\/p>\n<pre>JsonObjectRequest request = JsonObjectRequest(Request.Method.GET, url,  new ResponseListener(), new ErrorListener();<\/pre>\n<p><strong>First Parameter: Request.Method.GET &#8211;<\/strong> The GET is used to read. You can also use POST (to create), PUT (To update\/replace), DELETE (to delete), PATCH (to update\/modify) and more.<\/p>\n<p><strong>Second Parameter: URL &#8211;<\/strong> The url that\u00a0will response to the HTTP request.<\/p>\n<p><strong>Third Parameter: Successful Response Listener &#8211;<\/strong>\u00a0Where your data will go after the request is successfully complete.<\/p>\n<pre>private class ResponseListener implements Response.Listener{\r\n@Override\r\npublic void onResponse(JSONObject response){\r\n\r\n}\r\n}<\/pre>\n<p><strong>Fourth Parameter: Error Listener &#8211;<\/strong>\u00a0What will be told if there was a problem with your request. For example, you can display it in Log to see the error.<\/p>\n<pre>private class ErrorListener implements Response.ErrorListener{\r\n@Override\r\npublic void onErrorResponse(VolleyError error){\r\n\r\n}\r\n}<\/pre>\n<p>Now the last step is to add your request to Request queue and rest volley will handle for you.<\/p>\n<pre>queue.add(request);<\/pre>\n<p>Here you can also add more requests to the queue that you would like at one time and the response will be send to their respective response\/error classes.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-782\" src=\"\/programming\/wp-content\/uploads\/2017\/11\/Volley-Diagram-in-Android.png\" alt=\"Volley-Diagram-in-Android\" width=\"550\" height=\"448\" srcset=\"https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-Diagram-in-Android.png 550w, https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-Diagram-in-Android-300x244.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/p>\n<hr \/>\n<h4><strong>Volley Basic HTTP Example In Android Studio:<\/strong><\/h4>\n<p>In this example we have created a button and on click of a button a HTTP request will be send to server. The response from the server is then displayed using Toast on the screen.<\/p>\n<p>Below you can download code, see final output and step by step explanation of example.<\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"https:\/\/github.com\/abhisheksaini4\/BasicExample\" target=\"_blank\" rel=\"nofollow noopener\">Download Code<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-784\" src=\"\/programming\/wp-content\/uploads\/2017\/11\/Volley-Example-In-Android-Studio.png\" alt=\"Volley-Example-In-Android-Studio\" width=\"259\" height=\"460\" srcset=\"https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-Example-In-Android-Studio.png 259w, https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-Example-In-Android-Studio-169x300.png 169w\" sizes=\"auto, (max-width: 259px) 100vw, 259px\" \/><\/p>\n<p><strong>Step 1:<\/strong> Create a new project and name it VolleyBasicExample.<\/p>\n<p><strong>Step 2:<\/strong> Open res -&gt; layout -&gt; activity_main.xml (or) main.xml and add following code:<\/p>\n<p>In this step we create one Button which will be used to fire an HTTP request to server.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    tools:context=\"abhiandroid.com.volleybasicexample.MainActivity\"&gt;\r\n\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/buttonRequest\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:background=\"#414af4\"\r\n        android:text=\"Click Here To Send HTTP Request To Server And See Response Displayed As Toast\"\r\n        android:textColor=\"#ffffff\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_marginTop=\"50dp\" \/&gt;\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><strong>Step 3:<\/strong> To use volley library you will need to add the below dependency in your gradle build. <strong>Open build.gradle (Module: app) and add the below line in\u00a0dependencies and click sync now:<\/strong><\/p>\n<pre>apply plugin: 'com.android.application'\r\n\r\nandroid {\r\n    compileSdkVersion 25\r\n    buildToolsVersion \"25.0.3\"\r\n    defaultConfig {\r\n        applicationId \"abhiandroid.com.volleybasicexample\"\r\n        minSdkVersion 15\r\n        targetSdkVersion 25\r\n        versionCode 1\r\n        versionName \"1.0\"\r\n        testInstrumentationRunner \"android.support.test.runner.AndroidJUnitRunner\"\r\n    }\r\n    buildTypes {\r\n        release {\r\n            minifyEnabled false\r\n            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r\n        }\r\n    }\r\n}\r\n\r\ndependencies {\r\n    compile fileTree(dir: 'libs', include: ['*.jar'])\r\n    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {\r\n        exclude group: 'com.android.support', module: 'support-annotations'\r\n    })\r\n    compile 'com.android.support:appcompat-v7:25.3.1'\r\n    testCompile 'junit:junit:4.12'\r\n    compile 'com.android.volley:volley:1.0.0' \/\/ dependency file for Volley\r\n}<\/pre>\n<p><strong>Step 4:<\/strong> As our App will be sending request to the server and receiving response on button click which means it requires internet. <strong>So define internet permission in Android Manifest file.<\/strong><\/p>\n<p><strong>Manifest.xml code:<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    package=\"abhiandroid.com.volleybasicexample\"&gt;\r\n\r\n    &lt;uses-permission android:name=\"android.permission.INTERNET\" \/&gt;\r\n\r\n    &lt;application\r\n        android:allowBackup=\"true\"\r\n        android:icon=\"@mipmap\/ic_launcher\"\r\n        android:label=\"@string\/app_name\"\r\n        android:roundIcon=\"@mipmap\/ic_launcher_round\"\r\n        android:supportsRtl=\"true\"\r\n        android:theme=\"@style\/AppTheme\"&gt;\r\n        &lt;activity android:name=\".MainActivity\"&gt;\r\n            &lt;intent-filter&gt;\r\n                &lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\r\n\r\n                &lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\r\n            &lt;\/intent-filter&gt;\r\n        &lt;\/activity&gt;\r\n    &lt;\/application&gt;\r\n\r\n&lt;\/manifest&gt;<\/pre>\n<p><strong>Step 5:<\/strong> Now we will need to generate an HTTP request for our App. Below are the simple steps to generate it:<\/p>\n<p>a) First we will need sample JSON code. Below is the code I am using:<\/p>\n<p>Related Read: JSON Parsing Tutorial With Example in Android Studio<\/p>\n<pre>{\r\n    \"users\": [\r\n        {\r\n                \"id\": \"1087\",\r\n                \"name\": \"Abhishek Saini\",\r\n                \"email\": \"info@abhiandroid.com\",\r\n                \"gender\" : \"male\",\r\n                \"contact\": {\r\n                    \"mobile\": \"+91 0000000000\",\r\n                    \"home\": \"00 000000\",\r\n                    \"office\": \"00 000000\"\r\n                }\r\n        },\r\n        {\r\n                \"id\": \"1088\",\r\n                \"name\": \"Gourav\",\r\n                \"email\": \"gourav9188@gmail.com\",\r\n                \"gender\" : \"male\",\r\n                \"contact\": {\r\n                    \"mobile\": \"+91 0000000000\",\r\n                    \"home\": \"00 000000\",\r\n                    \"office\": \"00 000000\"\r\n                }\r\n        }\r\n  ]\r\n}<\/pre>\n<p>b) Now we will open the <a href=\"http:\/\/www.mocky.io\/\">mocky.io<\/a> and put the JSON code in it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-581\" src=\"\/programming\/wp-content\/uploads\/2017\/07\/Generate-HTTP-Response-For-Volley.jpg\" alt=\"Generate HTTP Response For Volley\" width=\"622\" height=\"317\" srcset=\"https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/07\/Generate-HTTP-Response-For-Volley.jpg 622w, https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/07\/Generate-HTTP-Response-For-Volley-300x153.jpg 300w\" sizes=\"auto, (max-width: 622px) 100vw, 622px\" \/><\/p>\n<p>c) Now click on the Generate My HTTP Response<\/p>\n<p>d) It will generate the link url which we will use in next step for sending request and getting HTTP response.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-582\" src=\"\/programming\/wp-content\/uploads\/2017\/07\/HTTP-Request-URL-For-Volley.jpg\" alt=\"HTTP Request URL For Volley\" width=\"543\" height=\"64\" srcset=\"https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/07\/HTTP-Request-URL-For-Volley.jpg 543w, https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/07\/HTTP-Request-URL-For-Volley-300x35.jpg 300w\" sizes=\"auto, (max-width: 543px) 100vw, 543px\" \/><\/p>\n<p><strong>Step 6:\u00a0<\/strong>Now open app -&gt; java -&gt; package -&gt; MainActivity.java and add the below code.<\/p>\n<p>In this step we will initialize the button and set on click listener on it. When the button is click, it will send HTTP request to the url that we generated in the previous step and display the response as Toast on the screen.<\/p>\n<p>Here we have used simple StringRequest and default RequestQueue that volley provide us.<\/p>\n<pre>package abhiandroid.com.volleybasicexample;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\nimport android.util.Log;\r\nimport android.view.View;\r\nimport android.widget.Button;\r\nimport android.widget.Toast;\r\n\r\nimport com.android.volley.Request;\r\nimport com.android.volley.RequestQueue;\r\nimport com.android.volley.Response;\r\nimport com.android.volley.VolleyError;\r\nimport com.android.volley.toolbox.StringRequest;\r\nimport com.android.volley.toolbox.Volley;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    private static final String TAG = MainActivity.class.getName();\r\n    private Button btnRequest;\r\n\r\n    private RequestQueue mRequestQueue;\r\n    private StringRequest mStringRequest;\r\n    private String url = \"http:\/\/www.mocky.io\/v2\/597c41390f0000d002f4dbd1\";\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n\r\n        btnRequest = (Button) findViewById(R.id.buttonRequest);\r\n\r\n        btnRequest.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v){\r\n\r\n                sendAndRequestResponse();\r\n\r\n            }\r\n        }\r\n\r\n        );\r\n\r\n    }\r\n\r\n    private void sendAndRequestResponse() {\r\n\r\n        \/\/RequestQueue initialized\r\n        mRequestQueue = Volley.newRequestQueue(this);\r\n\r\n        \/\/String Request initialized\r\n        mStringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener&lt;String&gt;() {\r\n            @Override\r\n            public void onResponse(String response) {\r\n\r\n                Toast.makeText(getApplicationContext(),\"Response :\" + response.toString(), Toast.LENGTH_LONG).show();\/\/display the response on screen\r\n\r\n            }\r\n        }, new Response.ErrorListener() {\r\n            @Override\r\n            public void onErrorResponse(VolleyError error) {\r\n\r\n                Log.i(TAG,\"Error :\" + error.toString());\r\n            }\r\n        });\r\n\r\n        mRequestQueue.add(mStringRequest);\r\n    }\r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Now run the App and click on the button. You will see HTTP response from server on click of it.<\/p>\n<hr \/>\n<h4><strong>Volley Advance Example in Android Studio:<\/strong><\/h4>\n<p>This is an advance example of Volley in which we will fetch data from server API using Volley. Our API contains three things title, image and category details which we will fetch in App using Volley.<\/p>\n<p><strong>Our Json API URL &#8211;<\/strong><\/p>\n<p><a href=\"http:\/\/mobileappdatabase.in\/demo\/smartnews\/app_dashboard\/jsonUrl\/single-article.php?article-id=71\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/mobileappdatabase.in\/demo\/smartnews\/app_dashboard\/jsonUrl\/single-article.php?article-id=71<\/a><\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"http:\/\/www.mediafire.com\/file\/cqcb3udfbec3rzc\/VolleyAdvance.zip\/file\" target=\"_blank\" rel=\"nofollow noopener\">Download Code<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-785\" src=\"\/programming\/wp-content\/uploads\/2017\/11\/Volley-Example-2-In-Android-Studio.png\" alt=\"Volley-Example-2-In-Android-Studio\" width=\"253\" height=\"450\" srcset=\"https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-Example-2-In-Android-Studio.png 253w, https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-Example-2-In-Android-Studio-169x300.png 169w\" sizes=\"auto, (max-width: 253px) 100vw, 253px\" \/><\/p>\n<p><strong>Creating New Project<\/strong>: Create a new Project\u00a0 File -&gt; New -&gt;Android Application Project<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 1:\u00a0<\/strong>Open your layout file of main activity\u00a0and add a ListView element.<\/p>\n<p><strong>actvity_main.xml<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n android:layout_width=\"match_parent\"\r\n android:layout_height=\"match_parent\"\r\n tools:context=\".MainActivity\" &gt;\r\n\r\n&lt;ListView\r\n android:id=\"@+id\/list\"\r\n android:layout_width=\"fill_parent\"\r\n android:layout_height=\"wrap_content\"\r\n android:dividerHeight=\"1dp\"\r\n \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><strong>Step 2:\u00a0<\/strong>We will now create another layout file for ListView row and name this file as <strong>list_row.xml<\/strong><\/p>\n<pre> &lt;?xml version=\"1.0\" encoding=\"utf-8\"?\/&gt;\r\n &lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n android:layout_width=\"fill_parent\"\r\n android:layout_height=\"wrap_content\"\r\n android:padding=\"8dp\" &gt;\r\n\r\n&lt;!-- Title --&gt;\r\n &lt;TextView\r\n android:id=\"@+id\/title\"\r\n android:layout_width=\"match_parent\"\r\n android:layout_height=\"wrap_content\"\r\n android:textSize=\"@dimen\/title\"\r\n android:layout_marginTop=\"10dp\"\r\n android:layout_marginBottom=\"20dp\"\r\n android:textColor=\"@color\/title\"\/&gt;\r\n\r\n&lt;!-- category--&gt;\r\n &lt;TextView\r\n android:id=\"@+id\/category\"\r\n android:layout_width=\"fill_parent\"\r\n android:layout_height=\"wrap_content\"\r\n android:textColor=\"@color\/category\"\r\n android:textSize=\"@dimen\/category\"\r\n android:textStyle=\"bold\"\r\n android:layout_below=\"@+id\/title\"\r\n android:layout_marginTop=\"20dp\"\r\n android:layout_marginLeft=\"1dp\" \/&gt;\r\n\r\n&lt;!-- Thumbnail Image --&gt;\r\n &lt;com.android.volley.toolbox.NetworkImageView\r\n android:id=\"@+id\/thumbnail\"\r\n android:layout_width=\"280dp\"\r\n android:layout_height=\"280dp\"\r\n android:layout_below=\"@+id\/category\"\r\n \/&gt;\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><strong>Step 3:<\/strong> Create a <strong>ImageClass.java<\/strong> and add the following code:<\/p>\n<p>This class takes care of caching images on disk.\u00a0A memory and disk cache allow\u00a0 \u00a0components to quickly reload processed images.<\/p>\n<p>A memory cache offers fast access to bitmaps at the cost of taking up valuable application memory. The\u00a0LruCache\u00a0class is particularly well suited to the task of caching bitmaps.<\/p>\n<pre>package com.example.abhishek.json;\r\n\r\nimport android.graphics.Bitmap;\r\nimport android.support.v4.util.LruCache;\r\n\r\nimport com.android.volley.toolbox.ImageLoader.ImageCache;\r\n\r\npublic class ImageClass extends LruCache&lt;String, Bitmap&gt; implements\r\n        ImageCache {\r\n    public static int getDefaultLruCacheSize() {\r\n        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() \/ 1024);\r\n        final int cacheSize = maxMemory \/ 8;\r\n\r\n        return cacheSize;\r\n    }\r\n\r\n    public ImageClass() {\r\n        this(getDefaultLruCacheSize());\r\n    }\r\n\r\n    public ImageClass(int sizeInKiloBytes) {\r\n        super(sizeInKiloBytes);\r\n    }\r\n\r\n    @Override\r\n    protected int sizeOf(String key, Bitmap value) {\r\n        return value.getRowBytes() * value.getHeight() \/ 1024;\r\n    }\r\n\r\n    @Override\r\n    public Bitmap getBitmap(String url) {\r\n        return get(url);\r\n    }\r\n\r\n    @Override\r\n    public void putBitmap(String url, Bitmap bitmap) {\r\n        put(url, bitmap);\r\n    }\r\n}<\/pre>\n<p><strong>Step 4<\/strong>: Next create a <strong>AppController<\/strong> class and add it in the <strong>AndroidManifest.xml<\/strong> to your <strong>&lt;application&gt;<\/strong> using name property to execute this class on starting of the application. Also add <strong>INTERNET<\/strong> permission as we are going to make network calls.<\/p>\n<p><strong>AppController.java<\/strong><\/p>\n<pre> package com.example.abhishek.json;\r\n\r\n import android.app.Application;\r\n import android.text.TextUtils;\r\n\r\n import com.android.volley.Request;\r\n import com.android.volley.RequestQueue;\r\n import com.android.volley.toolbox.ImageLoader;\r\n import com.android.volley.toolbox.Volley;\r\n\r\n public class AppController extends Application {\r\n\r\n public static final String TAG = AppController.class.getSimpleName();\r\n\r\n private RequestQueue mRequestQueue;\r\n private ImageLoader mImageLoader;\r\n\r\n private static AppController mInstance;\r\n\r\n @Override\r\n public void onCreate() {\r\n super.onCreate();\r\n mInstance = this;\r\n }\r\n\r\npublic static synchronized AppController getInstance() {\r\n return mInstance;\r\n }\r\n\r\npublic RequestQueue getRequestQueue() {\r\n if (mRequestQueue == null) {\r\n mRequestQueue = Volley.newRequestQueue(getApplicationContext());\r\n }\r\n\r\nreturn mRequestQueue;\r\n }\r\n\r\npublic ImageLoader getImageLoader() {\r\n getRequestQueue();\r\n if (mImageLoader == null) {\r\n mImageLoader = new ImageLoader(this.mRequestQueue,\r\n new ImageClass());\r\n }\r\n return this.mImageLoader;\r\n }\r\n\r\npublic  void addToRequestQueue(Request req, String tag) {\r\n \/\/ set the default tag if tag is empty\r\n req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);\r\n getRequestQueue().add(req);\r\n }\r\n\r\npublic  void addToRequestQueue(Request req) {\r\n req.setTag(TAG);\r\n getRequestQueue().add(req);\r\n }\r\n\r\npublic void cancelPendingRequests(Object tag) {\r\n if (mRequestQueue != null) {\r\n mRequestQueue.cancelAll(tag);\r\n }\r\n }\r\n }<\/pre>\n<p><strong>Step 5: Define internet permission and add AppController class in AndroidManifest.xml<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n &lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n package=\"com.example.abhishek.json\"&gt;\r\n &lt;uses-permission android:name=\"android.permission.INTERNET\" \/&gt;\r\n &lt;application\r\n android:allowBackup=\"true\"\r\n android:name=\".AppController\"\r\n android:icon=\"@mipmap\/ic_launcher\"\r\n android:label=\"@string\/app_name\"\r\n android:roundIcon=\"@mipmap\/ic_launcher_round\"\r\n android:supportsRtl=\"true\"\r\n android:theme=\"@style\/AppTheme\"&gt;\r\n &lt;activity android:name=\".MainActivity\"&gt;\r\n &lt;intent-filter&gt;\r\n &lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\r\n\r\n&lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\r\n &lt;\/intent-filter&gt;\r\n &lt;\/activity&gt;\r\n &lt;\/application&gt;\r\n\r\n&lt;\/manifest&gt;<\/pre>\n<p><strong>Step 6<\/strong>: Open<strong> build.gradle<\/strong> and add Volley library dependency.<\/p>\n<p>compile &#8216;com.android.volley:volley:1.0.0&#8217;<\/p>\n<pre> apply plugin: 'com.android.application'\r\n android {\r\n compileSdkVersion 26\r\n buildToolsVersion \"26.0.2\"\r\n defaultConfig {\r\n applicationId \"com.example.abhishek.jsonvolleyexample\"\r\n minSdkVersion 15\r\n targetSdkVersion 26\r\n versionCode 1\r\n versionName \"1.0\"\r\n testInstrumentationRunner \"android.support.test.runner.AndroidJUnitRunner\"\r\n }\r\n buildTypes {\r\n release {\r\n minifyEnabled false\r\n proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r\n }\r\n }\r\n }\r\n\r\ndependencies {\r\n compile fileTree(dir: 'libs', include: ['*.jar'])\r\n androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {\r\n exclude group: 'com.android.support', module: 'support-annotations'\r\n })\r\n compile 'com.android.support:appcompat-v7:26.+'\r\n compile 'com.android.support.constraint:constraint-layout:1.0.2'\r\n testCompile 'junit:junit:4.12'\r\n compile 'com.android.volley:volley:1.0.0'\r\n }<\/pre>\n<p><strong>Step 7<\/strong>: Create<strong> Model.java.<\/strong> This model class will be used to provide data to list view after parsing the json.<\/p>\n<pre> package com.example.abhishek.json;\r\n\r\n public class Model {\r\n private String title, category ,thumbnailUrl;\r\n\r\n public Model() {\r\n }\r\n public Model(String title, String category, String thumbnailUrl) {\r\n this.title=title;\r\n this.category=category;\r\n this.thumbnailUrl = thumbnailUrl;\r\n }\r\n\r\n public String getTitle() {\r\n return title;\r\n }\r\n\r\n public void setTitle(String title) {\r\n this.title = title;\r\n }\r\n\r\n public String getCategory() {\r\n return category;\r\n }\r\n\r\n public void setCategory(String category) {\r\n this.category = category;\r\n }\r\n\r\n public String getThumbnailUrl() {\r\n return thumbnailUrl;\r\n }\r\n\r\n public void setThumbnailUrl(String thumbnailUrl) {\r\n this.thumbnailUrl = thumbnailUrl;\r\n }\r\n }<\/pre>\n<p><strong>Step 8<\/strong>: Create a class <strong>CustomAdapter.java<\/strong> with below code. This is a custom adapter class which provides data to ListView<\/p>\n<pre> package com.example.abhishek.json;\r\n import android.app.Activity;\r\n import android.content.Context;\r\n import android.view.LayoutInflater;\r\n import android.view.View;\r\n import android.view.ViewGroup;\r\n import android.widget.BaseAdapter;\r\n import android.widget.TextView;\r\n\r\n import com.android.volley.toolbox.ImageLoader;\r\n import com.android.volley.toolbox.NetworkImageView;\r\n import java.util.List;\r\n\r\n public class CustomAdapter extends BaseAdapter {\r\n private Activity activity;\r\n private LayoutInflater inflater;\r\n private List modelItems;\r\n ImageLoader imageLoader = AppController.getInstance().getImageLoader();\r\n\r\n public CustomAdapter(Activity activity, List modelItems) {\r\n this.activity = activity;\r\n this.modelItems = modelItems;\r\n }\r\n\r\n @Override\r\n public int getCount() {\r\n return modelItems.size();\r\n }\r\n\r\n @Override\r\n public Object getItem(int location) {\r\n return modelItems.get(location);\r\n }\r\n\r\n @Override\r\n public long getItemId(int position) {\r\n return position;\r\n }\r\n\r\n @Override\r\n public View getView(int position, View convertView, ViewGroup parent) {\r\n\r\n if (inflater == null)\r\n inflater = (LayoutInflater) activity\r\n .getSystemService(Context.LAYOUT_INFLATER_SERVICE);\r\n if (convertView == null)\r\n convertView = inflater.inflate(R.layout.list_row, null);\r\n\r\n if (imageLoader == null)\r\n imageLoader = AppController.getInstance().getImageLoader();\r\n\r\n TextView title = (TextView) convertView.findViewById(R.id.title);\r\n TextView category = (TextView) convertView.findViewById(R.id.category);\r\n\r\n NetworkImageView thumbNail = (NetworkImageView) convertView\r\n .findViewById(R.id.thumbnail);\r\n\r\n \/\/ getting model data for the row\r\n Model m = modelItems.get(position);\r\n\r\n \/\/ title\r\n title.setText(\"Title: \" + String.valueOf(m.getTitle()));\r\n\r\n \/\/ category\r\n category.setText(\"Category: \"+ String.valueOf(m.getCategory()));\r\n\r\n \/\/ thumbnail image\r\n thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);\r\n\r\n return convertView;\r\n }}<\/pre>\n<p><strong>Step 9<\/strong>: Now open your main activity class (<strong>MainActivity.java<\/strong>) and add the below code. We created volley\u2019s JsonArrayRequest to get the json from url. Upon parsing the json, we stored all the json data into an ArrayList as Model objects.<\/p>\n<pre> package com.example.abhishek.json;\r\n import java.util.ArrayList;\r\n import java.util.List;\r\n import org.json.JSONArray;\r\n import org.json.JSONException;\r\n import org.json.JSONObject;\r\n\r\n import android.app.Activity;\r\n import android.app.ProgressDialog;\r\n import android.os.Bundle;\r\n import android.util.Log;\r\n import android.view.Menu;\r\n import android.widget.ListView;\r\n\r\n import com.android.volley.Response;\r\n import com.android.volley.VolleyError;\r\n import com.android.volley.VolleyLog;\r\n import com.android.volley.toolbox.JsonArrayRequest;\r\n\r\n public class MainActivity extends Activity {\r\n  \/\/ Log tag\r\n private static final String TAG = MainActivity.class.getSimpleName();\r\n\r\n private static final String url =\"  http:\/\/mobileappdatabase.in\/demo\/smartnews\/app_dashboard\/jsonUrl\/single-article.php?article-id=71\";\r\n private ProgressDialog pDialog;\r\n\r\n private List modelList = new ArrayList();\r\n private ListView listView;\r\n private CustomAdapter adapter;\r\n\r\n @Override\r\n protected void onCreate(Bundle savedInstanceState) {\r\n super.onCreate(savedInstanceState);\r\n setContentView(R.layout.activity_main);\r\n\r\n listView = (ListView) findViewById(R.id.list);\r\n adapter = new CustomAdapter(this, modelList);\r\n listView.setAdapter(adapter);\r\n\r\n pDialog = new ProgressDialog(this);\r\n \/\/ Showing progress dialog before making http request\r\n pDialog.setMessage(\"Loading...\");\r\n pDialog.show();\r\n\r\n \/\/ Creating volley request obj\r\n JsonArrayRequest movieReq = new JsonArrayRequest(url,\r\n new Response.Listener() {\r\n @Override\r\n public void onResponse(JSONArray response) {\r\n Log.d(TAG, response.toString());\r\n hidePDialog();\r\n\r\n \/\/ Parsing json\r\n for (int i = 0; i &lt; response.length(); i++) {\r\n try {\r\n\r\n JSONObject obj = response.getJSONObject(i);\r\n Model model = new Model();\r\n model.setTitle(obj.getString(\"title\"));\r\n model.setCategory(obj.getString(\"category\"));\r\n model.setThumbnailUrl(obj.getString(\"image\"));\r\n\r\n modelList.add(model);\r\n\r\n} catch (JSONException e) {\r\n e.printStackTrace();\r\n }\r\n\r\n}\r\n \/\/ notifying list adapter about data changes\u00a0so that it renders the list view with updated data\r\n adapter.notifyDataSetChanged();\r\n }\r\n }, new Response.ErrorListener() {\r\n @Override\r\n public void onErrorResponse(VolleyError error) {\r\n VolleyLog.d(TAG, \"Error: \" + error.getMessage());\r\n hidePDialog();\r\n\r\n}\r\n });\r\n\r\n\/\/ Adding request to request queue\r\n AppController.getInstance().addToRequestQueue(movieReq);\r\n }\r\n\r\n @Override\r\n public void onDestroy() {\r\n super.onDestroy();\r\n hidePDialog();\r\n }\r\n\r\n private void hidePDialog() {\r\n if (pDialog != null) {\r\n pDialog.dismiss();\r\n pDialog = null;\r\n }\r\n }\r\n\r\n @Override\r\n public boolean onCreateOptionsMenu(Menu menu) {\r\n \/\/ Inflate the menu; this adds items to the action bar if it is present.\r\n getMenuInflater().inflate(R.menu.main, menu);\r\n return true;\r\n }}<\/pre>\n<p><strong>Step 10:\u00a0<\/strong>Add the following code in xml files<\/p>\n<p><strong>values\u00a0 -&gt; colors.xml<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;resources&gt;\r\n\r\n    &lt;color name=\"category\"&gt;#b932ca&lt;\/color&gt;\r\n    &lt;color name=\"title\"&gt;#6b2cd9&lt;\/color&gt;\r\n\r\n&lt;\/resources&gt;<\/pre>\n<p><strong>values -&gt;dimens.xml<\/strong><\/p>\n<pre>&lt;resources&gt;\r\n\r\n    &lt;dimen name=\"title\"&gt;22dp&lt;\/dimen&gt;\r\n    &lt;dimen name=\"category\"&gt;20dip&lt;\/dimen&gt;\r\n\r\n&lt;\/resources&gt;<\/pre>\n<p><strong>\u00a0 values -&gt; strings.xml<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;resources&gt;\r\n\r\n    &lt;string name=\"app_name\"&gt;VolleyExample&lt;\/string&gt;\r\n\r\n&lt;\/resources&gt;<\/pre>\n<p><strong>\u00a0 values -&gt; styles.xml<\/strong><\/p>\n<pre>&lt;resources&gt;\r\n\r\n    &lt;style name=\"AppBaseTheme\" parent=\"android:Theme.Light\"&gt;\r\n    &lt;\/style&gt;\r\n    &lt;style name=\"AppTheme\" parent=\"AppBaseTheme\"&gt;\r\n    &lt;\/style&gt;\r\n\r\n&lt;\/resources&gt;<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Now run the App and test it once. You will see title, category and image in App which are fetched from server.<\/p>\n<hr \/>\n<h4><strong>Volley Custom RequestQueue Example in Android Studio:<\/strong><\/h4>\n<p>In the previous example we used newRequestQueue\u00a0method which uses default values to create RequestQueue and can be used for String Request. Now in this thrid method we will customized the request queue.<\/p>\n<p>Below you can download code, see final output and step by step explanation of example.<\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"http:\/\/www.mediafire.com\/file\/8a33c7z5axn8glc\/VolleyCustomRequestQueueExample.zip\/file\" target=\"_blank\" rel=\"nofollow noopener\">Download Code<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-786\" src=\"\/programming\/wp-content\/uploads\/2017\/11\/Volley-Custom-Request-Queue-Example-In-Android-Studio.png\" alt=\"Volley-Custom-Request-Queue-Example-In-Android-Studio\" width=\"259\" height=\"460\" srcset=\"https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-Custom-Request-Queue-Example-In-Android-Studio.png 259w, https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/11\/Volley-Custom-Request-Queue-Example-In-Android-Studio-169x300.png 169w\" sizes=\"auto, (max-width: 259px) 100vw, 259px\" \/><\/p>\n<p><strong>Step 1:<\/strong> Create a new project and name it VolleyCustomRequestQueueExample.<\/p>\n<p><strong>Step 2:<\/strong> Open res -&gt; layout -&gt; activity_main.xml (or) main.xml and add following code:<\/p>\n<p>In this step we create one Button which will be used to fire an HTTP request to server.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    tools:context=\"abhiandroid.com.volleycustomrequestqueueexample.MainActivity\"&gt;\r\n\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnRequest\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:background=\"#414af4\"\r\n        android:text=\"Click Here To Send HTTP Request To Server And See Response Displayed As Toast\"\r\n        android:textColor=\"#ffffff\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_marginTop=\"50dp\" \/&gt;\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><strong>Step 3:<\/strong> To use volley library you will need to add the below dependency in your gradle build. <strong>Open build.gradle (Module: app) and add the below line in\u00a0dependencies and click sync now:<\/strong><\/p>\n<pre>apply plugin: 'com.android.application'\r\n\r\nandroid {\r\n    compileSdkVersion 25\r\n    buildToolsVersion \"25.0.3\"\r\n    defaultConfig {\r\n        applicationId \"abhiandroid.com.volleycustomrequestqueueexample\"\r\n        minSdkVersion 15\r\n        targetSdkVersion 25\r\n        versionCode 1\r\n        versionName \"1.0\"\r\n        testInstrumentationRunner \"android.support.test.runner.AndroidJUnitRunner\"\r\n    }\r\n    buildTypes {\r\n        release {\r\n            minifyEnabled false\r\n            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r\n        }\r\n    }\r\n}\r\n\r\ndependencies {\r\n    compile fileTree(dir: 'libs', include: ['*.jar'])\r\n    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {\r\n        exclude group: 'com.android.support', module: 'support-annotations'\r\n    })\r\n    compile 'com.android.support:appcompat-v7:25.3.1'\r\n    compile 'com.android.support.constraint:constraint-layout:1.0.2'\r\n    testCompile 'junit:junit:4.12'\r\n\r\n    compile 'com.android.volley:volley:1.0.0' \/\/ dependency file for Volley\r\n}<\/pre>\n<p><strong>Step 4:<\/strong> As our App will be sending request to the server and receiving response on button click which means it requires internet. So define internet permission in Android Manifest file.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    package=\"abhiandroid.com.volleycustomrequestqueueexample\"&gt;\r\n\r\n    &lt;uses-permission android:name=\"android.permission.INTERNET\" \/&gt;\r\n\r\n    &lt;application\r\n        android:allowBackup=\"true\"\r\n        android:icon=\"@mipmap\/ic_launcher\"\r\n        android:label=\"@string\/app_name\"\r\n        android:roundIcon=\"@mipmap\/ic_launcher_round\"\r\n        android:supportsRtl=\"true\"\r\n        android:theme=\"@style\/AppTheme\"&gt;\r\n        &lt;activity android:name=\".MainActivity\"&gt;\r\n            &lt;intent-filter&gt;\r\n                &lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\r\n\r\n                &lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\r\n            &lt;\/intent-filter&gt;\r\n        &lt;\/activity&gt;\r\n    &lt;\/application&gt;\r\n\r\n&lt;\/manifest&gt;<\/pre>\n<p><strong>Step 5:<\/strong> Now we will need to generate an HTTP request for our App. Below are the simple steps to generate it:<\/p>\n<p>a) First we will need sample JSON code. Below is the code I am using:<\/p>\n<pre>{\r\n    \"users\": [\r\n        {\r\n                \"id\": \"1087\",\r\n                \"name\": \"Abhishek Saini\",\r\n                \"email\": \"info@abhiandroid.com\",\r\n                \"gender\" : \"male\",\r\n                \"contact\": {\r\n                    \"mobile\": \"+91 0000000000\",\r\n                    \"home\": \"00 000000\",\r\n                    \"office\": \"00 000000\"\r\n                }\r\n        },\r\n        {\r\n                \"id\": \"1088\",\r\n                \"name\": \"Gourav\",\r\n                \"email\": \"gourav9188@gmail.com\",\r\n                \"gender\" : \"male\",\r\n                \"contact\": {\r\n                    \"mobile\": \"+91 0000000000\",\r\n                    \"home\": \"00 000000\",\r\n                    \"office\": \"00 000000\"\r\n                }\r\n        }\r\n  ]\r\n}<\/pre>\n<p>b) Now we will open the <a href=\"http:\/\/www.mocky.io\/\">mocky.io<\/a> and put the JSON code in it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-581\" src=\"\/programming\/wp-content\/uploads\/2017\/07\/Generate-HTTP-Response-For-Volley.jpg\" alt=\"Generate HTTP Response For Volley\" width=\"622\" height=\"317\" srcset=\"https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/07\/Generate-HTTP-Response-For-Volley.jpg 622w, https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/07\/Generate-HTTP-Response-For-Volley-300x153.jpg 300w\" sizes=\"auto, (max-width: 622px) 100vw, 622px\" \/><\/p>\n<p>c) Now click on the Generate My HTTP Response<\/p>\n<p>d) It will generate the link url which we will use in next step for sending request and getting HTTP response.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-582\" src=\"\/programming\/wp-content\/uploads\/2017\/07\/HTTP-Request-URL-For-Volley.jpg\" alt=\"HTTP Request URL For Volley\" width=\"543\" height=\"64\" srcset=\"https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/07\/HTTP-Request-URL-For-Volley.jpg 543w, https:\/\/abhiandroid.com\/programming\/wp-content\/uploads\/2017\/07\/HTTP-Request-URL-For-Volley-300x35.jpg 300w\" sizes=\"auto, (max-width: 543px) 100vw, 543px\" \/><\/p>\n<p><strong>Step 5:<\/strong>\u00a0Now open app -&gt; java -&gt; package -&gt; MainActivity.java and add the below code.<\/p>\n<p>In this step we will initialize the button and set on click listener on it. When the button is click, it will send HTTP request to the url that we created in the previous step and display the response as Toast on the screen.<\/p>\n<p>Here we have used custom StringRequest and default RequestQueue that volley provide us.<\/p>\n<pre>package abhiandroid.com.volleycustomrequestqueueexample;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\nimport android.util.Log;\r\nimport android.view.View;\r\nimport android.widget.Button;\r\nimport android.widget.Toast;\r\n\r\nimport com.android.volley.Cache;\r\nimport com.android.volley.Network;\r\nimport com.android.volley.Request;\r\nimport com.android.volley.RequestQueue;\r\nimport com.android.volley.Response;\r\nimport com.android.volley.VolleyError;\r\nimport com.android.volley.toolbox.BasicNetwork;\r\nimport com.android.volley.toolbox.DiskBasedCache;\r\nimport com.android.volley.toolbox.HurlStack;\r\nimport com.android.volley.toolbox.StringRequest;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    private String server_url = \"http:\/\/www.mocky.io\/v2\/597c41390f0000d002f4dbd1\";\r\n    Button btnRequest;\r\n    RequestQueue requestQueue;\r\n    private static final String TAG = MainActivity.class.getName();\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n\r\n        btnRequest = (Button) findViewById(R.id.btnRequest);\r\n        Cache cache = new DiskBasedCache(getCacheDir(),1024*1024);\r\n        Network network = new BasicNetwork(new HurlStack());\r\n        requestQueue = new RequestQueue(cache,network);\r\n        requestQueue.start();\r\n\r\n        btnRequest.setOnClickListener(new View.OnClickListener(){\r\n            @Override\r\n            public void onClick (View v){\r\n\r\n                StringRequest stringRequest = new StringRequest(Request.Method.GET, server_url, new Response.Listener&lt;String&gt;() {\r\n                    @Override\r\n                    public void onResponse(String response) {\r\n                        Toast.makeText(getApplicationContext(),\"Response :\" + response.toString(), Toast.LENGTH_LONG).show();\/\/display the response on screen\r\n                        requestQueue.stop();\r\n                    }\r\n                }, new Response.ErrorListener() {\r\n                    @Override\r\n                    public void onErrorResponse(VolleyError error) {\r\n                        Log.i(TAG,\"Error :\" + error.toString());\r\n                    }\r\n                });\r\n\r\n                requestQueue.add(stringRequest);\r\n                    }\r\n                });\r\n            }\r\n\r\n    }\r\n\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Now run the App and click on button. You will see http response from server on click of it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Volley is a HTTP library developed by Google and was first introduced during Google I\/O 2013. This library is used to transmit data over the network. It actually makes networking faster and easier for Apps. It is available through AOSP(Android Open Source Project) repository. The volley library has the features like automatic scheduling of network &hellip; <a href=\"https:\/\/abhiandroid.com\/programming\/volley\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Volley Tutorial With Example In Android Studio<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"home.php","meta":{"footnotes":""},"class_list":["post-573","page","type-page","status-publish","hentry"],"psp_head":"<title>Volley Tutorial With Example In Android Studio \u2013 Abhi Android<\/title>\r\n<meta name=\"description\" content=\"Learn Volley web service step by step with example in Android Studio. Here we explain how to use it for fetching json data from server with 3 different types of examples.\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/programming\/volley\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/programming\/wp-json\/wp\/v2\/pages\/573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/programming\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/abhiandroid.com\/programming\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/programming\/wp-json\/wp\/v2\/comments?post=573"}],"version-history":[{"count":5,"href":"https:\/\/abhiandroid.com\/programming\/wp-json\/wp\/v2\/pages\/573\/revisions"}],"predecessor-version":[{"id":996,"href":"https:\/\/abhiandroid.com\/programming\/wp-json\/wp\/v2\/pages\/573\/revisions\/996"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/programming\/wp-json\/wp\/v2\/media?parent=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}