微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 创建包并发送到新活动

我在一个活动中创建一个包,然后在另一个活动中提取

这是它在主要活动中创建的时间

//Create bundle to reference values in next class
                Bundle bundle = new Bundle();
                bundle.putInt("ODD",odd);
                bundle.putInt("EVEN",even);
                bundle.putInt("SMALL",small);
                bundle.putInt("BIG",big);
                //After all data has been entered and calculated,go to new page for results
                Intent myIntent = new Intent();
                myIntent.setClass(getBaseContext(),Results.class);
                startActivity(myIntent);
                //Add the bundle into myIntent for referencing variables
                myIntent.putExtras(bundle);

然后,当我提取其他活动

//Extract the bundle from the intent to use variables
    Bundle bundle = getIntent().getExtras();
    //Extract each value from the bundle for usage
    int odd = bundle.getInt("ODD");
    int even = bundle.getInt("EVEN");
    int big = bundle.getInt("BIG");
    int small = bundle.getInt("SMALL");

当我在第二个活动中提取包时应用程序崩溃.
但是当我注释掉束的提取时.该应用运行正常.所以我把它缩小到了那个范围.

我的日志猫并没有真正解释错误是什么,或者我只是不明白它

想法?

解决方法

您在调用startActivity(myIntent)后添加以下代码;
//Add the bundle into myIntent for referencing variables
                myIntent.putExtras(bundle);

把它放在startActivity(myIntent)之前;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐