java - 你如何通过 2 个 Activity 传递一个字符串?

标签 java android android-intent

我需要在一个 Activity 中发送来自用户的输入,该 Activity 将其发送到 activity2,然后 activity2 将来自 activity1 的输入发送到 Activity 3。从视觉上看,它会:

activity1 有一个编辑文本字段,可将输入发送到 activity2activity2 使用相同的输入并将其发送到 activity3

(activity1) --String--> (activity2) --String--> (activity3)

我是否必须从 activity1 获取 Intent 并将其从 activity2 中的 onclick 方法发送到 activity3

最佳答案

String passString= "information im sending";
Intent intent = new Intent(this, secondActivity.class);
intent.putExtras("DataKey", passString);
startActivity(intent);

//in your second activity
Intent intent = getIntent();
String recieveString = intent.getStringExtra("DataKey");

//repeat the same in your second activity but this time the string will change
Intent intent = new Intent(this, thirdActivity.class);
intent.putExtras("DataKey", recieveString);
startActivity(intent);

//in your third activity
Intent intent = getIntent();
String recieveString2 = intent.getStringExtra("DataKey");

关于java - 你如何通过 2 个 Activity 传递一个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26810254/

相关文章:

php - 如何阻止 android 应用程序显示我的网站?

android - 可跨文本在对话框 fragment 中不起作用

android - intent.getCategories() 为空,尽管它已设置

android - 如何在 Android 上的多个 Activity 之间发送回值

android - 如何自动更新应用程序;安卓

java - 调试和正常执行模式之间的不同行为 - WeakReference 处理

java - tomcat 7.0 和 jax-ws 2.2.5 内存泄漏

android - 如何在 Windows 7 的模拟器上安装 facebook api?

java - assertTrue() 不输入内部函数参数

java - 用于匹配变量和逗号之间的空格的正则表达式