捆绑堆叠是否有启动性()?
我有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从现有意图中获取数据,您需要调用
getIntent()。getExtras()
wich return cruntr currentbundle
。您正在使用新实例创建secondBundle
,但是您需要使用bundle secondbundle = getIntent()。getExtras();
To get data from existing intent you need to call
getIntent().getExtras()
wich return currentBundle
. You are creatingsecondBundle
with new instance but you need to useBundle secondBundle = getIntent().getExtras();