我在一个活动中创建一个包,然后在另一个活动中提取它
这是在主要活动中创建的时间
//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");
当我在第二个活动中提取包时,应用程序崩溃了。 但是当我注释掉束的提取时。该应用运行正常。所以我把它缩小到了那个。
我的日志猫并没有真正解释错误是什么,或者我只是不理解
想法?
答案 0 :(得分:3)
您在致电startActivity(myIntent);
//Add the bundle into myIntent for referencing variables
myIntent.putExtras(bundle);
将它放在startActivity(myIntent);