我目前正在解析一個web文件,然後在完成時設置5個textview值,但是,每當活動關閉並重新打開時,它需要再次訪問頁面解析並顯示值,我如何防止它不得不?防止每次打開活動時都必須加載TextViews?
它應該指出,數據變化相當有規律,所以我不能簡單地保存價值永遠。
public void gatherStockDetails(String symb) {
AsyncHttpClient client = new AsyncHttpClient();
client.get("url" + symb + "&f=snpog",
new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
Log.e("KFF-a", response);
stockinfo = response.split(",");
setTextViews(stockinfo[0].replaceAll("[^a-zA-Z0-9.%+ -]+", ""),
stockinfo[1].replaceAll("[^a-zA-Z0-9.%+ -]+", ""),
stockinfo[2].replaceAll("[^a-zA-Z0-9.%+ -]+", ""),
stockinfo[3].replaceAll("[^a-zA-Z0-9.%+ -]+", ""),
stockinfo[4].replaceAll("[^a-zA-Z0-9.%+ -]+", ""));
}
@Override
public void onFailure(Throwable arg0, String arg1) {
super.onFailure(arg0, arg1);
}
});
}
和
public void setTextViews(String Symbol, String Name, String PClose, String Open, String Low) {
final Animation in = new AlphaAnimation(0.0f, 1.0f);
in.setDuration(500);
tvName.setText(Name.replace("Corpora", "Corporation"));
tvName.startAnimation(in);
tvSymbol.setText(Symbol);
tvSymbol.startAnimation(in);
tvSymbol.setText(PClose);
tvPClose.startAnimation(in);
tvLow.setText(Low);
tvLow.startAnimation(in);
tvOpen.setText(Open);
tvOpen.startAnimation(in);
}
對不起,我沒有提到,這是在片段上的活動,因而不存在onRestoreInstance狀態。
參見[傳輸數據使用同步適配器(http://developer.android.com/training/sync-adapters/index.html) – ramaral