android - 如何从为结果开始的 Activity 返回字符串

标签 android

我已经为结果启动了 Activity,但是如何从该 Activity 返回类似字符串的参数?

最佳答案

只需使用以下代码块:

Intent intent=new Intent();
intent.putExtra("RESULT_STRING", string);
setResult(RESULT_OK, intent);
finish();

在调用 Activity 的 onActivtyResult 方法中从此 Intent 中获取值:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == CREATE_REQUEST_CODE) {
      if (resultCode == RESULT_OK) {
        //Use Data to get string
        String string = data.getStringExtra("RESULT_STRING");
      }
   }
}

关于android - 如何从为结果开始的 Activity 返回字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9225871/

相关文章:

ANDROID_HOME 未设置(VSTS 代理在 OS X 上作为服务运行)

发送包含超过一定大小的字节数据的对象时出现Java StreamCorruptedException

java - ArrayList.Remove 在第一次调用时不起作用

android - 约束布局与相对布局

android - 在不同布局的 ViewPager Indicator 中设置数据

android - Appium - 无法使用 xpath 定位 android 元素

android - 如何从字符串而不是 R.id 中查找 View

java - 修剪文本 - 当最后输入大量空格键时

java - android 中简单的 fragment tabhost

android - Proguard 错误代码 1