捆绑堆叠是否有启动性()?

发布于 2025-02-10 00:37:44 字数 727 浏览 1 评论 0原文

我有3个活动,A,B和C。如果我将意图从A到B

//from A
Intent i1 = new Intent(A.this, B.class);
Bundle firstBundle = new Bundle();
firstBundle.putString("Key1", "Value1");
i1.putExtras(firstBundle);

//to B
Intent i1 = getIntent();

,如果我将另一个从B到C添加到C中,

//from B
Intent i2 = new Intent(B.this, C.class);
Bundle secondBundle = new Bundle();
secondBundle.putString("Key2", "Value2");
i2.putExtras(secondBundle);

//to C
Intent i2 = getIntent();

我可以在C中使用它吗?

Intent i3 = getIntent();
Bundle thirdBundle = i3.getExtras();
String firstString = thirdBundle.getString("firstKey");

即使来自其他意图,我也可以从FirstBundle获得项目吗?如果没有,我该如何实现?这样做甚至有效吗?有更好的方法吗?

I have 3 activities, A, B, and C. If I pass an intent from A to B

//from A
Intent i1 = new Intent(A.this, B.class);
Bundle firstBundle = new Bundle();
firstBundle.putString("Key1", "Value1");
i1.putExtras(firstBundle);

//to B
Intent i1 = getIntent();

And if I add another bundle from B to C

//from B
Intent i2 = new Intent(B.this, C.class);
Bundle secondBundle = new Bundle();
secondBundle.putString("Key2", "Value2");
i2.putExtras(secondBundle);

//to C
Intent i2 = getIntent();

Would I be able to use this in C?

Intent i3 = getIntent();
Bundle thirdBundle = i3.getExtras();
String firstString = thirdBundle.getString("firstKey");

Can I get the items from firstBundle even though it is from a different intent? If not, how can I make it happen? Is it even efficient to do it this way? Is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑梦风尘 2025-02-17 00:37:44

要从现有意图中获取数据,您需要调用getIntent()。getExtras() wich return cruntr current bundle。您正在使用新实例创建secondBundle,但是您需要使用bundle secondbundle = getIntent()。getExtras();

To get data from existing intent you need to call getIntent().getExtras() wich return current Bundle. You are creating secondBundle with new instance but you need to use Bundle secondBundle = getIntent().getExtras();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文