【发布时间】:2023-03-25 10:10:01
【问题描述】:
我正在尝试将字符串从一个活动传递到另一个活动。我似乎无法获得额外的意图。我哪里错了?
这里是代码
将额外内容放入意图中:
public void onClick(View v) {
// TODO Auto-generated method stub
String string = editTextFeild.getText().toString();
Intent i = new Intent("com.com.com.otherclass");
i.putExtra("dat", string);
startActivity(new Intent("com.com.com.otherclass"));
}
从 Intent 中获取数据(在 com.com.com.otherclass 中):
Bundle bundle = getIntent().getExtras();
if (bundle != null){
String string = bundle.getString("dat");
textView.setText(string);
}
附言这些不是我在代码中使用的实际名称:)
提前致谢:)
【问题讨论】:
-
你检查过editTextField不为空吗?
-
是的,每次我测试它,它都有一个价值:)
-
你为什么要构建一个新的 Intent 甚至不使用它...?
-
那是我的问题。我现在改了:)