這是我從我所說的second Activity
first activity
代碼:什麼是意圖從onActivityResult參數
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT){
startActivityForResult(new Intent("chap.two.Chapter2Activity2"),request_Code);
}
return false;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == request_Code) {
if (resultCode == RESULT_OK)
Toast.makeText(this,data.getData().toString(),Toast.LENGTH_SHORT).show();
}
}
這裏是chap.two.Chapter2Activity2
代碼:
Button n = (Button) findViewById(R.id.btn_OK);
n.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent data = new Intent();
//---get the EditText view---
EditText txt_username =(EditText) findViewById(R.id.txt_username);
//---set the data to pass back---
data.setData(Uri.parse(txt_username.getText().toString()));
setResult(RESULT_OK, data);
//---closes the activity---
finish();
}
});
在這裏我看到setResult(RESULT_OK, data)
有兩個參數但
onActivityResult(int requestCode, int resultCode, Intent data)
有三個,我想知道onActivityResult
如何獲得第三個參數的值?它如何運作,任何人都可以告訴我?爲什麼不是這個錯誤?
只要檢查該ansswer http://stackoverflow.com/a/25196220/1587156 –