这是一个非常大的问题,它真的困扰着我。 我有一个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