我想把一些字符串數據從 sub activity 發送到 main activity,然後在 edit text 字段中顯示數據。
sub activity :
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent in = new Intent();
in.setClass(getApplicationContext(),
DelaySmsActivity.class);
in.putExtra("values", stringDataForSend);
setResult(RESULT_OK, in);
finish();
}
});
main activity代碼,我想從中獲取值:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
parametar = data.getStringExtra("values");
editTextField.setText(parametar);
}
運行過後,editTextField 是空的,怎麼解決呢?
present activity 是 X,另一個 Activity 是 Y
Intent main= new Intent(X.this, Y.class);
main.putExtra("key", "somevalue");
X.this.startActivity(main);
在 Y Activity onCreate
Intent intent = getIntent();
String value= intent.getStringExtra("key");