Create a package and submit a new activity

I create a package in one action, then extracting it into another action

here when he was created in his 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 retrieve another 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"); 

When the application crashes, when I retrieve the package for the second action. But when I comment on the extraction of the package. The application is working fine. So I narrowed it down to that.

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

ideas?

+7
source share
1 answer

You add below code after calling startActivity(myIntent);

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

Put this immediately before startActivity(myIntent);

+3
source

All Articles