2012-02-16 12 views
7

I "m creación de un lote en una actividad, su separación, en otra actividadcreación de paquete y el envío a la nueva actividad

aquí es cuando se crea en la que la actividad principal

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

Luego, cuando me extraer en la otra actividad

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

la aplicación se bloquea cuando estoy extrayendo el paquete en la segunda actividad. Pero cuando comento a cabo la extracción de la bu ndle. La aplicación funciona bien Así que lo he reducido a eso.

Mi gato de registro no explica realmente lo que es el error, o apenas no entenderlo

ideas?

+0

pregunta fácil. Está llamando a putExtras (paquete) después de comenzar la nueva actividad. –

Respuesta

3

Está añadiendo a continuación el código después de llamar startActivity(myIntent);

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

Ponga esto justo antes de startActivity(myIntent);

Cuestiones relacionadas