android - 在更多 Activity 中使用 bundle ?

标签 android

我有主要 Activity 和另外两个 Activity (第二个和第三个)。我在主要 Activity 和 Intent 中创建了一个包,就像这样Intent intent = new Intent(this,second.class); 我想在第三个 Activity 中使用 get extras。像 bundle comes = getIntent().getExtras();。有可能吗?为什么不可以?

最佳答案

and I want to use get extras in third activity. like bundle comes = getIntent().getExtras();. is it possible or why not?

您只能从将启动您的第三个 Activity 的 Intent 中getExtras()。所以换句话说,如果您的 MainActivity 启动第三个 Activity,您可以在第三个 Activity 中检索数据,如果您将它们附加到启动第三个 Activity 的 Intent 中:

// this is calling from MainActivity
Intent intent = new Intent(this, Third.class);
intent.putExtras(bundle);

如果 MainActivity 不启动第三个 Activity,则您无法执行此操作。但是您可以从第二个 Activity 中检索第三个 Activity 中的数据(在这里您必须再次将数据附加到 Intent):

// this is calling from SecondActivity
Intent intent = new Intent(this, Third.class);
intent.putExtras(bundle);

关于android - 在更多 Activity 中使用 bundle ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20331575/

相关文章:

android - ffmpeg 为 Android 编译

java - 可用蓝牙设备列表

android - 使用自定义 Loader 时,不会在 ViewPager fragment 上调用 ​​onResume()

android - 在 Android 中失去焦点时不隐藏对话框

android - 如何像网络服务一样使用 Google 云端硬盘

android - tabwidget 没有出现在 Eclipse 图形布局编辑器中

android - SurfaceHolder.setFormat(PixelFormat.RGBA_8888) 在某些设备上失败,而在其他设备上失败

android - 尽管升级了包装器,但运行 gradle 命令时出错

java - Android-蓝牙。空指针

java - 舞台对象不会在每个屏幕上居中和缩放相同