以下是我的代码,用于处理 setResult
。我总是会得到ResultCode = 0
。
@Override
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
Debug.i("Response Status Complete " + response.code());
if (response.code() == 200) {
Debug.i("Response Status Complete " + response);
mSectionTopic.isComplete = 1;
mSectionTopic.status = "completed";
Intent intent = new Intent();
intent.putExtra(Util.getIntentName("sectionTopic"), mSectionTopic);
intent.putExtra(Util.getIntentName("challengeId"), "AIzaSyBkSGK9geQ4QbnvXcQQ_m2JScd7r89xnJs");
intent.putExtra(Util.getIntentName("position"), mPosition);
setResult(Activity.RESULT_OK, intent);
finish();
} else {
showError(getString(R.string.text_post_question_failed));
}
但是如果代码onBackPressed();
的结果代码正常工作。
我的代码有什么问题?
--
这是我的onActivityResult()
函数。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CODE && resultCode == Activity.RESULT_OK) {
if (data == null) return;
int position = data.getIntExtra(Util.getIntentName("position"), 0);
mAdapter.setComplete(position);
mAdapter.notifyDataSetChanged();
}
}
onBackPressed
中使用Intent
和setResult
进程,我就无法得到resultCode = 0
。 - Menda