浅析Activity之间的相互调用
//在按键按下后,调用第二个实体,第二个实体处理完数据后再传给第一个实体
btn3.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
final int RG_REQUEST = 0;
Intent intent = new Intent();
//作为接受数据端
intent.setClass(Activity1.this, Activity2.class);
startActivityForResult(intent, RG_REQUEST);
/////////////////////
}
});
}
//处理接收的数据
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
super.onActivityResult(requestCode, resultCode, data)
if(resultCode==RESULT_OK)
{
//接收数据
Bundle bundle =data.getExtras();
double aplpa=bundle.getDouble("aplpa");
String mode=bundle.getString("mode");
String time=bundle.getString("time");
}
}
// //////////////////
// 点击按键后,确认返回处理
// ////////////
btn1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Bundle bundle = new Bundle();
bundle.putInt("time", time);
bundle.putInt("alpha", aplpa);
bundle.putInt("mode", mode);
Intent intent = new Intent(Activity2.this,Activity1.class);
intent.putExtras(bundle);
setResult(RESULT_OK, intent);
Activity.this.finish();
}
});