问一个关于Intent的putExtra方法的问题?
有3个Activity 分别是A,B,C
A里面Intent 首先 putExtra("1","1");putExtra("2","2");setclass(A.this,B.class);
B里面Intent 首先 putExtra("3","3");setclass(B.this,C.class);
C里面的Intent 能收到这3个键值吗?
也就是说在A里面发送了2个键值后跳到B,B发送了一个键值后跳到C,C里面能收到这3个键值吗?
------解决方案--------------------
呵呵,取不到。
但,必须在B中new Intent()然后setBundle,参数是A中的Bundle,
------解决方案--------------------
每次都是一个新的intent,你可以将第一个intent中取出bundle,然后再将需要存的值存到bundle里,再将bundle存到新的intent,就可以了
------解决方案--------------------
从A-->B 新建一个intent 获取从A到B的intent,这个intent中保存了1,2的值;
final Intent getIntent=getIntent();
从B-->C 新建一个intent 把1,2的值添加进去
Intent intent=new Intent();
intent.putExtra("3", "3");
intent.putExtra("1",getIntent.getStringExtra("1"));
intent.putExtra("2",getIntent.getStringExtra("2"));
在B中有两个intent
这样C里就能接受3个值了
------解决方案--------------------
很显然只能取到"3"对应的"3",
因为A发送的intent限定了B(setclass(A.this,B.class);)能接收到键值对("1","1")("2","2"),同理,B发送的intent限定了C(setclass(B.this,C.class);)能收到键值对("3","3")
------解决方案--------------------
封装对象,googl+百度
如果你要再C中取的A中的键值对的话,你的再B中通过一个Bundle存取,然后在set,这样就可以在C中取得了