无法理解 "name" 在活动之间使用意图放置和获取数据的价值

Can't get my head around the "name" value in putting and getting data from intents for use between activities

我有两个活动,我试图在使用 Intent extra 之间共享一个值。从我通过调试得知的情况来看,该值已正确放置在意图中,并且当在原始 activity 中调用 onResult() 时,该值似乎保持不变。但是我的 TextView 显示 Textnull 而不是在第二个 activity.

的文本编辑中输入的文本

我对 Intent extras 不理解的是 "name" 值的作用及其指向的含义,我想这就是问题的核心(尽管我和可能错了)。

我将从我的两个活动中复制代码,如果你们能告诉我如何正确使用名称值,或者如果我完全错误地识别了问题,那就太好了。

The initial activity that launches the second and waits for a result back.

The second activity in which text is entered and result returned with the data packaged in the intent.

@npace 说得对。

在你的enterClicked()中,你需要写:

resultIntent.putExtra("text", mEditText.getText().toString());

getText() returns 你是 Editable 的一个实例,但你实际上需要一个字符串。