Activity1
復制代碼 代碼如下:
//在按鍵按下後,調用第二個實體,第二個實體處理完數據後再傳給第一個實體
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");
}
}
Activity2
復制代碼 代碼如下:
// //////////////////
// 點擊按鍵後,確認返回處理
// ////////////
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();
}
});