2015-08-28 47 views
0

如何獲取Android AQuery從互聯網下載數據,如果可能的話,否則 - 從緩存? 我的代碼:AQuery AJAX緩存

final GetFeedsAjaxCallback ac = new GetFeedsAjaxCallback(...); 
aq.ajax(feed, XmlDom.class, -1, ac); 

如果沒有互聯網連接我的代碼不能正常工作。

+0

什麼啊?!? :-) Java中的Ajax?!?這是一個我不知道的框架嗎?或者有沒有特別的理由不使用AsyncTask? –

+0

@Neo,https://code.google.com/p/android-query/wiki/AsyncAPI – Prostoplus

回答

0

使用代碼:

AQuery aq; 
    //... 
    final GetFeedsAjaxCallback ac = new GetFeedsAjaxCallback(...); 
    aq.ajax(feed, XmlDom.class, -1, ac); 

...

if (status.getCode() != 200 || xml == null) 
try { 
    xml = new com.androidquery.util.XmlDom(new FileInputStream(aq.getCachedFile(url))); 
    } 
    catch (Exception e){} 
//do something