title: Android Volley Post Request not Sent to server and not refreshed
body: <p>I am using Volley library to load images and to request result from a rest api, the library is working fine and i am doing some lazy good work with it, however sometimes and randomly (i couldn't detect the cause yet) the application is not refreshing the results after a request made by a users.</p>
  
  <p>the application i am creating shows a flow of news in multiple languages, when i change the user language from ENGLiSH to FRENCH i do rebuild my json request and i send it to the server, but i am surprise to see the response contains ENGLISH text, i use the same request in another Rest Tool (chrome extension) and the response sends back FRENCH text! intriguing isn't it.</p>
  
  <p>I have logged to the server and i have monitored the logs and i was surprised to see that all my requests is not reaching my server and the logs is showing old values, i said to myself maybe there is no internet in my android device so i have removed the application and reinstall it and the log file start dancing with requests from my phone.. so the device have internet connection and it's calling the server correctly ..</p>
  
  <p>so i thought there is maybe some tweeking needed to Volley configuration to not cache when it's not needed, below sample code from my apps:</p>
  
  <p><strong>VolleyHelper.java</strong></p>
  
  <pre><code> import android.content.Context;
  
  import com.android.volley.RequestQueue;
  import com.android.volley.toolbox.ImageLoader;
  import com.android.volley.toolbox.Volley;
  //import com.github.volley.example.toolbox.BitmapLruCache;
  
  /**
   * Helper class that is used to provide references to initialized RequestQueue(s) and ImageLoader(s)
   */
  public class VolleyHelper {
      private static final int MAX_IMAGE_CACHE_ENTIRES  = 100;
      private static RequestQueue mRequestQueue;
      private static ImageLoader mImageLoader;
  
      private VolleyHelper() {
      }
  
      public static void init(Context context) {
          mRequestQueue = Volley.newRequestQueue(context);
          mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(MAX_IMAGE_CACHE_ENTIRES));
      }
  
      public static RequestQueue getRequestQueue() {
          if (mRequestQueue != null) {
              return mRequestQueue;
          } else {
              throw new IllegalStateException("RequestQueue not initialized");
          }
      }
  
      /**
       * Returns instance of ImageLoader initialized with {@see FakeImageCache} which effectively means
       * that no memory caching is used. This is useful for images that you know that will be show
       * only once.
       */
      public static ImageLoader getImageLoader() {
          if (mImageLoader != null) {
              return mImageLoader;
          } else {
              throw new IllegalStateException("ImageLoader not initialized");
          }
      }
  }
  </code></pre>
  
  <p><strong>AppController.java</strong></p>
  
  <pre><code>import android.app.Application;
  import android.text.TextUtils;
  
  import com.android.volley.Request;
  import com.android.volley.RequestQueue;
  import com.android.volley.toolbox.ImageLoader;
  import com.android.volley.toolbox.Volley;
  
  public class AppController extends Application {
  
      public static final String TAG = AppController.class
              .getSimpleName();
  
      private RequestQueue mRequestQueue;
      private ImageLoader mImageLoader;
  
      private static AppController mInstance;
  
      @Override
      public void onCreate() {
          super.onCreate();
          mInstance = this;
      }
  
      public static synchronized AppController getInstance() {
          return mInstance;
      }
  
      public RequestQueue getRequestQueue() {
          if (mRequestQueue == null) {
              mRequestQueue = Volley.newRequestQueue(getApplicationContext());
          }
  
          return mRequestQueue;
      }
  
      public ImageLoader getImageLoader() {
          getRequestQueue();
          if (mImageLoader == null) {
              mImageLoader = new ImageLoader(this.mRequestQueue,
                      new LruBitmapCache());
          }
          return this.mImageLoader;
      }
  
      public &lt;T&gt; void addToRequestQueue(Request&lt;T&gt; req, String tag) {
          // set the default tag if tag is empty
          req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
          getRequestQueue().add(req);
      }
  
      public &lt;T&gt; void addToRequestQueue(Request&lt;T&gt; req) {
          req.setTag(TAG);
          getRequestQueue().add(req);
      }
  
      public void cancelPendingRequests(Object tag) {
          if (mRequestQueue != null) {
              mRequestQueue.cancelAll(tag);
          }
      }
  }
  </code></pre>
  
  <p><strong>JSONParser.java</strong></p>
  
  <pre><code>import java.io.InputStream;
  import java.util.List;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.UnsupportedEncodingException;
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.client.utils.URLEncodedUtils;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.util.Log;
  
  public class JSONParser {
  
      static InputStream is = null;
      static JSONObject jObj = null;
      static String json = "";
  
      // constructor
      public JSONParser() {
  
      }
  
      // function get json from url
      // by making HTTP POST or GET method
      public JSONObject makeHttpRequest(String url, String method,
              List&lt;NameValuePair&gt; params) {
  Log.e("MakeHttpRequest : ", "--MakeHttpRequest---");
          // Making HTTP request
          try {
  
              // check for request method
              if(method == "POST"){
                  // request method is POST
                  // defaultHttpClient
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  HttpPost httpPost = new HttpPost(url);
                  httpPost.setEntity(new UrlEncodedFormEntity(params));
  
                  HttpResponse httpResponse = httpClient.execute(httpPost);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  is = httpEntity.getContent();
  
              }else      if(method == "GET"){
                  // request method is GET
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  String paramString = URLEncodedUtils.format(params, "utf-8");
                  url += "?" + paramString;
                  HttpGet httpGet = new HttpGet(url);
  
                  HttpResponse httpResponse = httpClient.execute(httpGet);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  is = httpEntity.getContent();
              }
  
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          try {
              BufferedReader reader = new BufferedReader(new InputStreamReader(
                      is, "utf-8"), 8);
              StringBuilder sb = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) {
                  sb.append(line + "\n");
              }
              is.close();
              json = sb.toString();
          } catch (Exception e) {
              Log.e("Buffer Error", "Error converting result " + e.toString());
          }
  
          // try parse the string to a JSON object
          try {
              jObj = new JSONObject(json);
          } catch (JSONException e) {
              Log.e("JSON Parser", "Error parsing data " + e.toString());
          }
  
          // return JSON String
          return jObj;
  
      }
  }
  </code></pre>
  
  <p><strong>My Request from MainActivity.java</strong></p>
  
  <pre><code>AppController p = AppController.getInstance();
          HashMap&lt;String, Object&gt; params = new HashMap&lt;String, Object&gt;();
  
          params.put("sectionId", C.ART); // section of news 
          params.put("pageNumber", 0); // page number
          params.put("numberOfRecords", 10); // number of records we want to retrieve
  
          toggleLoader(isRefresh);
  
          JsonObjectRequest req = new JsonObjectRequest(C.SERVER_URL + C.getNews,
                  new JSONObject(params), new Listener&lt;JSONObject&gt;() {
                      @Override
                      public void onResponse(JSONObject response) {
  
                          String Array = response.toString();
                          adapter.refreshAdapter(getRowList(Array), isRefresh);
                          // setRefreshActionButtonState(false);
                          loadingMore = false;
                          isRefresh = false;
                          toggleLoader(isRefresh);
                      }
                  }, new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          VolleyLog.d(TAG, "Error: " + error.getMessage());
                          // hideProgressDialog();
                          Toast.makeText(getBaseContext(),
                                  "Error while getting Data", Toast.LENGTH_SHORT)
                                  .show();
                      }
                  });
  
          // Adding request to request queue
          p.addToRequestQueue(req, tag_json_arry);
  </code></pre>
  
  <p><strong>RefreshAdapter method from my News Adapter:</strong></p>
  
  <pre><code>public synchronized void refreshAdapter(List&lt;NewsModel&gt; dataitems, boolean isRefresh) {
          if(isRefresh)
              items.clear();
          items.addAll(dataitems);
          notifyDataSetChanged();
      }
  </code></pre>
  
  <p>Any help or idea are welcome.</p>