0
我有一個活動, 它的一些片段我要去數據庫獲取數據。問題在回來的路上。android在活動中保存活動
當後退按鈕按下時,片段將再次獲取數據。 我需要它只獲取一次數據(數據不會丟失)。 什麼是正確的做法?
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.from_opening_to_plan, container,
false);
setRetainInstance(true); //work only once.
// --- Sending Data to Server -----//
startLoading();
ParseCloud.callFunctionInBackground(funcName, h,
new FunctionCallback<Object>() {
@SuppressWarnings("unchecked")
public void done(Object result, ParseException e) {
if (e == null) {
results = ((HashMap<String, Object>) result);
stopLoading();
}
else{
stopLoading();
}
}
});
return v;
}
protected void startLoading() {
proDialog = new ProgressDialog(this.getActivity(),ProgressDialog.THEME_HOLO_DARK);
proDialog.setMessage("Loading ...");
proDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
proDialog.setCancelable(false);
proDialog.show();
}
protected void stopLoading() {
proDialog.dismiss();
proDialog = null;
// Build the page from the results.
makePage();
}
@SuppressWarnings("deprecation")
public void makePage() {
LinearLayout ll_buttons = (LinearLayout) v2
.findViewById(R.id.buttons_frame);
LinearLayout ll_question = (LinearLayout) v2
.findViewById(R.id.question_frame);
TextView tv = new TextView(container2.getContext());
String text = (((HashMap) results).get("textPrefix").toString());
text = text.replace("\r", "\r\n\r\n ");
....
....
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
....
}
});
ll_buttons.addView(b1);
}
v2.setBackgroundDrawable(SMApplication.selectedVertical.gd);
}
它仍然工作的同 – igor 2014-10-21 07:56:06
你還沒有發佈任何代碼,所以它不可能看到會發生什麼 – 2014-10-21 07:57:34
添加一個代碼,也許我應該用onBack()使用一些東西? – igor 2014-10-21 08:12:45