实现
activity1 跳转到 activity2
activity1 跳转到 activity3
用startActivityForResult的好处: activity2 /activity3 可以向activity1 返回值
[java]view plaincopy
print?
Intent bintent =newIntent(MainActivity.this,Activity2.class);
bintent.putExtra("na", myname);
startActivityForResult(bintent, 11);//11数字随便写,用来标志是拿个活动返回的值
[java]view plaincopy
print?
在activity2中写下要返回的数据
[java]view plaincopy
print?
@Override
publicbooleanonKeyDown(intkeyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() ==0)
{//按下的如果是BACK,同时没有重复
System.out.printf("按下返回键");
intentResult.putExtra("flog","yes");
this.setResult(1, intentResult);//
finish();
returntrue;
}
returnsuper.onKeyDown(keyCode, event);
}
在activity1 中接受返回来的值
[java]view plaincopy
print?
protectedvoidonActivityResult(intrequestCode,intresultCode, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {// 通过requestCode来辨别数据来自哪个activity返回的
case11:// 取
switch(resultCode) {// 通过resultCode来辨别activity的相应处理方法
case1:
if(data!=null)
{
String flog=data.getStringExtra("flog");
}
break;
}
}