2012-02-16 44 views
7

我「米創造了一個活動捆綁,然後在另一個活動創建包發送到新的活動

這裏提取它,當它在他主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); 

後來,當我提取的其他活動

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

當我提取束的第二個活動。 但應用程序崩潰時我註釋掉BU的提取ndle。該應用程序運行良好。所以我把它縮小到了這個範圍。

我的日誌貓並沒有真正解釋錯誤是什麼,或者我只是不明白它

想法?

+0

簡單的問題致電startActivity(myIntent);

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

將這個。開始新活動後,您正在調用putExtras(包)。 – 2013-08-09 15:39:10

回答

3

你加入以下代碼後,之前startActivity(myIntent);