每次我从下面的 AcitvityResult 函数中选择一个。我的活动刷新和之前从该活动设置的数据被重置为空。通过分析,我认为这与onActivityResult有关。我的问题是是否可以阻止活动结果刷新活动,因为我不想丢失以前设置的数据。这是我的 onactivity 结果函数。
更新: ClassA.class
final Button btnValidate = (Button) findViewById(R.id.btnValidate);
btnValidate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mSelectedCalendar != null) {
final Intent intent = new Intent();
intent.setAction(String.valueOf(Utils
.CalenderToInteger(mSelectedCalendar)));
setResult(RESULT_OK, intent);
} else {
setResult(RESULT_CANCELED);
}
finish();
}
});
ClassB.class
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_DEPARTURE_DATE && resultCode == RESULT_OK) {
Calendar cal = Utils.IntegerToCalendar(Integer.parseInt(data
.getAction()));
Utils.setDate(mTxtDepartureDate, cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
if (mTxtReturnDate.getTag() != null) {
Date departureDate = (Date) mTxtDepartureDate.getTag();
Calendar cal2 = Calendar.getInstance();
cal2.setTime(departureDate);
Utils.SetDayElapsed(cal2, 7);
Utils.setDate(mTxtReturnDate, cal2.get(Calendar.YEAR),
cal2.get(Calendar.MONTH),
cal2.get(Calendar.DAY_OF_MONTH));
}
} else if (requestCode == REQUEST_RETURN_DATE
&& resultCode == RESULT_OK) {
Calendar cal = Utils.IntegerToCalendar(Integer.parseInt(data
.getAction()));
Utils.setDate(mTxtReturnDate, cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
}
}