交付结果失败 结果信息
2022-09-02 04:05:11
有很多人在stackoverflow上遇到过同样的错误,但我无法在这些帖子中找到任何相关的解决方案。我的主要活动是使用 startActivityForResult() 启动一个新活动 (SecondActivity);然后,SecondActivity 使用 onBackPressed() 返回一些数据;和 putExtra();
主要活动摘录.java:
public void addNewNote(View v){
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("Source", "NEW");
startActivityForResult(intent, 1); //1 is the result code
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.v("TAG", data.getStringExtra("Note"));
if (requestCode == 1) {
if(resultCode == RESULT_OK){
listItems.add(data.getStringExtra("Note"));
Log.v("TAG", data.getStringExtra("Note"));
adapter.notifyDataSetChanged();
listView.invalidateViews();
}
if (resultCode == RESULT_CANCELED) {
}
}
}
第二活动摘录.java:
@Override
public void onBackPressed() {
super.onBackPressed();
if (mainTextField.getText() != null){
Intent returnIntent = new Intent();
returnIntent.putExtra("Note",mainTextField.getText());
setResult(RESULT_OK, returnIntent);
finish();
} else {
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
}
}
日志: