标签:
第一个Activity
public class MainActivity extends ActionBarActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.startActy);
tv=(TextView) findViewById(R.id.textView);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(MainActivity.this,TheAty.class);
// Bundle bundle = new Bundle();
// bundle.putString("name", "王城");
// bundle.putInt("age", 26);
//i.putExtras(bundle);
i.putExtra("data", new User("wangcheng",25));
startActivityForResult(i, 0);;
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
tv.setText(data.getData().toString());
};
第二个Activity
public class TheAty extends ActionBarActivity {
EditText ed;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_the_aty);
TextView tv = (TextView) findViewById(R.id.otherActy);
ed = (EditText) findViewById(R.id.editText);
btn = (Button) findViewById(R.id.btn);
Intent i = getIntent();
//Bundle data = i.getExtras();
//Bundle data = i.getBundleExtra("data");
//User user=(User) i.getSerializableExtra("data")
User user=(User) i.getParcelableExtra("data");
tv.setText(String.format("User info(name=%s,age=%d)",user.getName(),user.getAge()));
//tv.setText(data.getString("name"));
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String uriString = ed.getText().toString();
Uri data = Uri.parse(uriString);
Intent intent = new Intent(null, data);
setResult(0,intent);
finish();
}
});
}
标签:
原文地址:http://www.cnblogs.com/cityking/p/a009.html