【问题标题】:Why am i not able to get Extras from the intent this way?为什么我不能以这种方式从意图中获得额外信息?
【发布时间】:2012-09-03 09:28:55
【问题描述】:

在之前的活动中我是这样做的:

int entryId = 10;
intent.putExtra("entry_id", entryId);

然后在结果活动中

首先我尝试了这个:

entry_id = this.getIntent().getExtras().getInt("entry_id");

它总是给我默认值0

但我改成这样了:

entry_id = this.getIntent().getIntExtra("entry_id", 1);

它给出了正确的值 (10)。

为什么会这样?

【问题讨论】:

  • 为您的意图附加名称定义常量。这样可以避免像这样的拼写错误。

标签: android android-intent extra


【解决方案1】:

在您的第一种情况下,将 entry_Id 更改为 entry_id

【讨论】:

    【解决方案2】:

    试试这个entry_id = this.getIntent().getIntExtra("entry_Id", 1);

    更改是在id 中使用I。这是您的 get() 中的资本

    原因是key区分大小写

    【讨论】:

      【解决方案3】:

      您应该使用entry_id 而不是entry_Id

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-27
        • 1970-01-01
        • 2019-05-26
        • 1970-01-01
        相关资源
        最近更新 更多