onActivityResult ResultCode 始终为 0
onActivityResult ResultCode always 0
我总是用下面的代码得到 ResultCode = 0
。
这是我的进程代码 setResult
@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();
resultcode 工作正常。
我的代码有什么问题?
--
这是我的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();
}
}
您需要正确实施 startActivityForResult()
和 onActivityResult()
。按照此处的说明进行操作 -
我总是用下面的代码得到 ResultCode = 0
。
这是我的进程代码 setResult
@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();
resultcode 工作正常。
我的代码有什么问题?
--
这是我的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();
}
}
您需要正确实施 startActivityForResult()
和 onActivityResult()
。按照此处的说明进行操作 -