這是一個非常大的問題,它真的困擾着我。 我有一個web服務,我通過josn從我的數據中獲取數據,我需要我的數據進行更新。android-如何避免緩存json
問題是這樣的,我打開我的應用程序,它連接到webservice,它會得到非常舊的數據,我刪除應用程序並再次安裝它,清除緩存和數據,沒有任何工作,它仍然會得到舊數據。
我該如何解決? 這是獲取數據的代碼:
public class Spots_tab1_json {
static String response = null;
public final static int GET = 1;
public final static int POST = 2;
public Spots_tab1_json() {
}
public String makeServiceCall(String url, int method) {
return this.makeServiceCall(url, method, null);
}
public String makeServiceCall(String url, int method,
List<NameValuePair> params) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
if (method == POST) {
HttpPost httpPost = new HttpPost(url);
if (params != null) {
httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
}
httpResponse = httpClient.execute(httpPost);
} else if (method == GET) {
if (params != null) {
String paramString = URLEncodedUtils.format(params, "UTF-8");
url += "?" + paramString;
}
HttpGet httpGet = new HttpGet(url);
httpResponse = httpClient.execute(httpGet);
}
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
}
感謝
請命名約定,這會傷害我的眼睛:class Spots_tab1_json ... – 2Dee 2014-09-30 08:10:40