创建包和发送到新的活动 [英] creating bundle and sending over to new activity

查看:135
本文介绍了创建包和发送到新的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我M在一个活动创建一个包,然后在另一个活性提取它

I"m creating a bundle in one activity, then extracting it in another activity

在这里,当它在他的主要活动的创建是

here is when it's created in he main activity

//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);

然后,当我解压的其他活动。

Then when I extract on the other activity

//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");

当我解压的第二个活动捆绑应用程序崩溃。
但是,当我注释掉束的提取。该应用程序运行正常。所以,我已经将范围缩小到这一点。

The application crashes when I'm extracting the bundle on the second activity. But when I comment out the extraction of the bundle. The app runs fine. So I've narrowed it down to that.

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

My log cat doesn't really explain what the error is, or i just dont understand it

想法?

推荐答案

您在呼唤后添加以下code startActivity(myIntent);

You are adding below code after calling startActivity(myIntent);

//Add the bundle into myIntent for referencing variables
                myIntent.putExtras(bundle);

之前 startActivity(myIntent)将这个;

这篇关于创建包和发送到新的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆