我目前正在解析一个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