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)之前;

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...