Activity间的跳转和数据传递
Button bt; EditText et; TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.sendimpl); bt=(Button) findViewById(R.id.mybut); et=(EditText) findViewById(R.id.etqq); tv=(TextView) findViewById(R.id.tvdd); bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String valueString=et.getText().toString(); Intent t=new Intent(SendImpl.this,ReviceImpl.class); t.putExtra("value", valueString); startActivityForResult(t, 1); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK){ String valString=data.getStringExtra("val"); tv.setText(valString); }else{ tv.setText("取消操作"); } }
TextView tv; Button bu; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.recevie); tv=(TextView) findViewById(R.id.tvqq); bu=(Button) findViewById(R.id.retbut); Intent t=getIntent(); String vaString=t.getStringExtra("value"); tv.setText(vaString); bu.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getIntent().putExtra("val", "second reslut"); setResult(RESULT_OK,getIntent()); finish(); } }); }