2013-08-27 125 views
2

我試圖爲另一個應用程序的活動(這也是我的)創建一個快捷方式。該快捷方式正確啓動活動,但只有其中一個額外收到(或發送,我不知道)。請參見下面的代碼:通過意圖傳遞兩個值

//Setting up the intent 
Intent intent = new Intent(); 
intent.putExtra("num", 12); 
intent.putExtra("name", "something"); 
intent.setComponent(new ComponentName 
    ("com.myanother.app","com.myanother.app.MyActivity")); 

而其他活動:

Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
     int num = extras.getInt("num"); //this worked 
     String name = extras.getString("name"); //this gets null 

那麼,什麼是錯的?如果我犯了一些錯誤,對我的英語感到抱歉。

+0

檢查,如果您正在使用相同的密鑰「姓名」發送任何其他數據或chnage此鍵,我試圖改變密鑰名其他一些字 –

+0

,但它沒也沒用。並沒有其他數據具有相同的密鑰。 – jorgemoreira

回答

1

試試這個:

Bundle bund = new Bundle(); 

bund.putInt("num",12); 
bund.putString("name","hello world"); 

Intent intent = new Intent(); 

intent.putExtras(bund); 

intent.setComponent(new ComponentName 
("com.myanother.app","com.myanother.app.MyActivity")); 
1

而不是試圖放入多個額外的東西,你可以嘗試通過一個額外的包。看看at the first answer of this question。問題是類似的,解決方案應該是工作。