프로젝트에서 발리를 사용하여 인터넷의 데이터를 구문 분석합니다. 나는 성공적으로 데이터를 캐시하고 거기에서 데이터를 검색 할 수 및 캐시를 사용할 수없는 경우 다음 코드에 의해 네트워크 분석 :발리를 사용하여 새 데이터 만 사용할 수있는 경우 네트워크에서로드하는 방법
Cache cache = GlobalData.getInstance().getRequestQueue().getCache();
Entry entry = cache
.get("http://10.10.10.22/emaildata/getcurrentuser.php");
if (entry != null) {
try {
String data = new String(entry.data, "UTF-8");
JSONArray array = new JSONArray(data);
setParsedValue(array);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
JsonArrayRequest jArrayRequest = new JsonArrayRequest(
"http://10.10.10.22/emaildata/getcurrentuser.php",
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray array) {
setParsedValue(array);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG)
.show();
}
});
GlobalData.getInstance().addToRequestQueue(jArrayRequest);
}
가 지금은 데이터가 항상 새로운 데이터까지 캐시에서로드 것이라고합니다 지금까지 내가했던 onPause();
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
GlobalData
.getInstance()
.getRequestQueue()
.getCache()
.invalidate("http://10.10.10.22/emaildata/getcurrentuser.php",
true);
}
때로는 작동하지만 때로는 일을 나던에 다음과 같은, 즉 네트워크 URL을 볼 수 있습니다 내 장치를 다시 시작하기 위해 내가 가진 대부분의 시간은 새로운 데이터 위치에 대한 awared하세요 나는 대신에 네트워크에서 파싱하거나 cac에서로드하는 데이터 변경을 즉시 얻을 수있는 방법을 원하고 있습니다. 그렇지 않으면?
plz 신중하게 내 질문을 읽어보십시오. – Reyjohn