怎么样在三个Activity间传值

移动开发 码拜 9年前 (2015-11-13) 920次浏览

RT  例如 本人I有三个Activity A B C 一个值M,首先值M从A传到B,B在接受到值M后在传到C,现在问题出在B上,怎么在B上接收到值M后传给C  有具体的代码吗 本人按照
A传到B
Intent intent = new Intent(A.this,B.class);//设置跳转         
         Bundle bundle=new Bundle();
bundle.putCharSequence(“user”, yhm);
intent.putExtras(bundle);
startActivity(intent);
B接受值在传到C
                Intent intent=getIntent();
        Bundle bundle=intent.getExtras();
        String name=bundle.getString(“user”);
                 Intent intent = new Intent(B.this,C.class);//设置跳转         
         Bundle bundle=new Bundle();
bundle.putCharSequence(“yh”, name);
intent.putExtras(bundle);
startActivity(intent);
C接受值
                     Intent intent=getIntent();
              Bundle bundle=intent.getExtras();
             String name1=bundle.getString(“yh”);
问一下本人的代码有问题吗
解决方案:40分
B中的bundle名重复了,还有没有用到bundle可以就省去new bundle,直接改成intent.putExtra(“key”, “value”);发送intent;取得的时候直接intent.getStringExtra(“key”);

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么样在三个Activity间传值
喜欢 (0)
[1034331897@qq.com]
分享 (0)