android跳轉到另一個類再返回當前類和值
第一步:在A類中點擊按鈕時調用B類A類中:
int OUTBILL_CODE = 10;//全局啊
case R.id.diyoutbill:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(ctx, Itemdiydown.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent,OUTBILL_CODE);
break;
第二步:
B類中:
Bundle bundle = new Bundle();
bundle.putString("downtype",pubdowntype);
bundle.putString("startDate",pubstartDate);
bundle.putString("endDate", pubendDate);
Itemdiydown.this.setResult(RESULT_OK, this.getIntent().putExtras(bundle));
Itemdiydown.this.finish();//關閉當前窗口
第三類:
返回A類中:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OUTBILL_CODE&& resultCode == RESULT_OK) {//
Bundle bundle = data.getExtras();
startDate = bundle.getString("startDate");
endDate = bundle.getString("endDate");
downtype = bundle.getString("downtype");
//執行事件
}
}