当finish一个Activity时传值
Fragment中代码:
Intent intent=new Intent();
intent.setClass(getContext(),LoginActivity.class);
startActivityForResult(intent,0x002);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode==0x002&&resultCode==0x001){
//当LoginActivity finish后,就会调用这里,data为值
textview.setText(data.getStringExtra("name"));
}
super.onActivityResult(requestCode, resultCode, data);
}
Activity中的代码:
Intent intent=new Intent();
intent.putExtra("name",Name);
intent.putExtra("statu",Statu);
setResult(0x001,intent);
finish();