Activity之间传递数据
Activity1
Intent intent= new Intent(MainActivity.this,SecondActivity.class);
Bundle bundle= new Bundle();
bundle.putString("username","lizhch");
intent.putExtra("busername", bundle);
startActivityForResult(intent, 0);//启动之后要求接受回传的值
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {//这个方法用来监听回传的数据
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
data.getExtras().get("password"); -print xxx
}
Activity2
String username = getIntent().getBundleExtra("busername").getString("username");
Toast.makeText(SecondActivity.this, username, 1).show();
Intent intent = new Intent();
intent.putExtra("password", "xxx");
setResult(RESULT_OK, intent); //设置回传的数据,注意 RESULT_OK
finish();