gpt4 book ai didi

android - 将数据从一个 Activity 传递到另一个 Activity

转载 作者:行者123 更新时间:2023-11-29 18:18:50 26 4
gpt4 key购买 nike

<分区>

在 Activity1 中,我输入了一些数据,例如姓名和地址。当我点击下一步按钮时,会出现另一个输入表单。我想要做的是,当我点击 BACK 时,我将返回到 Activity1 并显示我之前在那里输入的数据。

请帮助:)

=============

更新: Activity 1

private void startActivityForResult()
{
TextView textname = (TextView) findViewById(R.id.username);
TextView textaddress = (TextView) findViewById(R.id.useraddress);

Intent intent = new Intent(this, GetInformation.class);
//intent.putExtras(getIntent());

intent.putExtra("username", textname.getText().toString());
intent.putExtra("useradd", textaddress.getText().toString());
startActivityForResult(intent, 0);
}

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
TextView textname = (TextView) findViewById(R.id.username);
TextView textaddress = (TextView) findViewById(R.id.useraddress);
textname.setText(data.getStringExtra("returnname").toString());
textaddress.setText(data.getStringExtra("returnadd").toString());
}

Activity 2

private void startActivityForResult()
{
final String username;
final String useraddress;
Intent intent = getIntent();

//intent.putExtras(getIntent());

username = getIntent().getStringExtra("username");
useraddress = getIntent().getStringExtra("useradd");

intent.putExtra("returnname", username);
intent.putExtra("returnadd", useraddress);

setResult(0, intent);
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com