use*_*632 8 android android-intent
我在一个活动中创建一个包,然后在另一个活动中提取它
这是它在主要活动中创建的时间
//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);
Run Code Online (Sandbox Code Playgroud)
然后,当我提取其他活动
//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");
Run Code Online (Sandbox Code Playgroud)
当我在第二个活动中提取包时应用程序崩溃.但是当我注释掉束的提取时.该应用运行正常.所以我把它缩小到了那个范围.
我的日志猫并没有真正解释错误是什么,或者我只是不理解它
想法?
您在调用后添加以下代码startActivity(myIntent);
//Add the bundle into myIntent for referencing variables
myIntent.putExtras(bundle);
Run Code Online (Sandbox Code Playgroud)
把这个放在前面startActivity(myIntent);
| 归档时间: |
|
| 查看次数: |
18131 次 |
| 最近记录: |