发送EditText数据从一个活动到另一个



我该如何在edittext中输入文本并将该数据发送到不同的活动?

的例子:如果用户在EditText中输入文本,并按下提交按钮,我希望将输入的文本存储在EditText中,并在活动时将其显示在不同的活动中。

  1. EditText获取信息,其中:getText()https://developer.android.com/reference/android/widget/EditText.html getText ()

2。有两种方式可以发送数据。

//Create the bundle
Bundle bundle = new Bundle();
//Add your data from getFactualResults method to bundle
bundle.putString("CONSTANT_NAME", EditText.getText);
//Add the bundle to the intent
browserIntent.putExtras(bundle);
startActivity(browserIntent);

在另一个活动中,你应该使用:

Bundle bundle = getIntent().getExtras();
//Extract the data…
String value = bundle.getString("CONSTANT_NAME");        
if (bundle.containsKey(MainActivity.CONSTANT_NAME))    {
    ....
}

最新更新