1 2 3 4 | Intent it = new Intent(MainActivity. this ,OtherActivity. class ); it.putExtra( "one" , a); //传送数据 it.putExtra( "two" , b); startActivityForResult(it, 1 ); //启动一个线程等待返回结果,1是请求码,开发者自己填,作为标志 |
1 2 3 4 5 6 7 8 9 10 | protected void onActivityResult( int requestCode, int resultCode, Intent data) {
super .onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 ) { //是否等于请求码,验证是否是等待的那个
if (resultCode == 2 ) { //接受方发回的返回码,验证是否是等待的一方发回的,是才接收。
int i = data.getIntExtra( "three" , 0 );
three.setText(i + "" );
}
} } |
1 2 3 | Intent it = getIntent(); int a = it.getIntExtra( "one" , 0 ); int b = it.getIntExtra( "two" , 0 ); |
1 2 3 4 5 | Intent it = new Intent(); int three = Integer.parseInt(edittext.getText().toString()); it.putExtra( "three" ,three); setResult( 2 ,it); //设置结果码 finish(); //结束该进程,执行完该语句自动返回结果。 |