笔记如下
- 开启某个某个结果为了activity,在开启activity的同时还传过去一个resquestCode,用于标记
startActivityForResult(intent,2);
在被开启的activity中处理数据后,返回数据,数据就会传递到onActivityResult()方法中
Intent intent = new Intent();
intent.putExtra("contact",contact);
setResult(2,intent);
finish();
入口activity中
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 1){
if (data != null) {
String contact = data.getStringExtra("contact");
ed_contact.setText(contact);
}
}else if(resultCode == 2){
if (data != null){
String msg = data.getStringExtra("msg");
sms_body.setText(msg);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
网友评论