【问题标题】:Pass two values via Intent通过 Intent 传递两个值
【发布时间】:2013-08-27 15:01:57
【问题描述】:

我正在尝试为另一个应用程序的活动创建快捷方式(这也是我的)。快捷方式正确启动了活动,但只收到了两个额外内容之一(或发送,我不知道)。请看下面的代码:

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

那么,怎么了?如果我犯了一些错误,请原谅我的英语。

【问题讨论】:

  • 检查您是否正在发送具有相同键“名称”的任何其他数据或将此键更改为其他单词
  • 我尝试更改密钥名称,但也没有用。并且没有其他数据具有相同的键。

标签: android android-intent android-widget


【解决方案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"));

【讨论】:

    【解决方案2】:

    您可以尝试将捆绑包作为额外内容传递,而不是尝试放入多个附加内容。看at the first answer of this question。问题类似,解决方案应该可行。

    【讨论】:

      猜你喜欢
      • 2011-07-19
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      • 2017-04-19
      • 1970-01-01
      相关资源
      最近更新 更多