2012-02-16 9 views
7

I "m tworząc wiązkę w jednej czynności, a następnie wyodrębnianie go w innej działalnościtworząc wiązkę i wysyłanie nad do nowej działalności

tu jest, kiedy to utworzony w he głównej działalności

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

Wtedy kiedy wyodrębnić na pozostałej działalności

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

awarii aplikacji, kiedy jestem wydobywania pakiet na drugim aktywności. Ale kiedy wykomentuj ekstrakcję bu ndle. Aplikacja działa dobrze. Więc ograniczyłem to do tego.

Mój dziennik kot nie naprawdę wyjaśnić, co jest błąd, albo ja po prostu nie rozumiem

pomysły?

+0

proste pytanie. Dzwonisz do putExtras (bundle) po rozpoczęciu nowej aktywności. –

Odpowiedz

3

możliwość dodawania kodu poniżej po wywołaniu startActivity(myIntent);

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

umieścić to tuż przed startActivity(myIntent);

Powiązane problemy