我想把一些字符串数据从 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 是空的,怎么解决呢?
2 回答
GCT1015
TA贡献1827条经验 获得超4个赞
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");
添加回答
举报
0/150
提交
取消