2013-08-27 94 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。问题是类似的,解决方案应该是工作。