如何通过编程方式清除android中特定服务的缓存

如何通过编程方式清除android中特定服务的缓存,android,caching,http-post,offline,Android,Caching,Http Post,Offline,我的应用程序通常通过调用服务或使用POST方法的URL从服务器获取数据,在POST方法中,参数被添加到URL。为此,我使用了一个JSONParser类向服务器请求数据,然后以JSON格式获取数据,如下代码所示: public class JSONParser { static InputStream is = null; static JSONObject jObj = null; JSONArray jArr = null; static String jso

我的应用程序通常通过调用服务或使用POST方法的URL从服务器获取数据,在POST方法中,参数被添加到URL。为此,我使用了一个
JSONParser
类向服务器请求数据,然后以
JSON
格式获取数据,如下代码所示:

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    JSONArray jArr = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }

    public JSONArray getJSONFromUrl(String url) {

        // Making HTTP request
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);


            HttpResponse httpResponse = httpClient.execute(httpPost);

            HttpEntity httpEntity = httpResponse.getEntity();

            is = httpEntity.getContent();           

        } catch (UnsupportedEncodingException e) {

        } catch (ClientProtocolException e) {

        } catch (IOException e) {

        }

        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();
            Log.e("JSON Parser", json );
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            JSONTokener jt = new JSONTokener(json);
            Object rootElement = jt.nextValue();
            if (rootElement instanceof JSONObject) {
               // You got an object from the jresponse
                jObj = new JSONObject(json);
            } else if (rootElement instanceof JSONArray) {
                 jArr = new JSONArray(json);

                 return jArr;
               // You got a JSON array
            }
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jArr;

    }
}
要调用此类,我使用以下代码段:

String njoftime_url = URL[0];

                // Creating JSON Parser instance
                JSONParser jParser = new JSONParser();

                // getting JSON string from URL
                njoftimeInformation = jParser.getJSONFromUrl(njoftime_url);
...................
问题是,当我第一次呼叫服务时,我会收到一些格式良好的数据,但当我断开手机与互联网的连接并拨打电话时,即使手机断开连接,我仍然会收到相同的数据

我的猜测是,数据保存在Android程序的缓存中,但有时这会给我错误的数据,例如,当我将参数从:

http://www.server.com/path/service_name.ashx?code=MAKINA_CATEGORY
致:

没有连接到internet,或者连接丢失,它根据第一个参数提供数据,我猜这些数据保存在缓存中

我的问题是,如何删除缓存中仅针对某些服务和URL保存的此类数据


任何帮助都将不胜感激

请从实例变量中删除static…我想它会起作用。@ArunKumar谢谢,它解决了问题,我想把这个问题标记为已解决,但我不知道在哪里。请从实例变量中删除static…我想它会起作用。@ArunKumar谢谢,它解决了问题,我想把这个问题标记为已解决,但我不知道在哪里。请从实例变量中删除static…我认为它会起作用。@ArunKumar谢谢,它解决了问题,我想把这个问题标记为已解决,但我不知道在哪里。
http://www.server.com/path/service_name.ashx?code=Prona_CATEGORY