【问题标题】:Can't get extras from a PendingIntent无法从 PendingIntent 中获得额外信息
【发布时间】:2014-08-13 21:38:18
【问题描述】:

当我尝试取回通知的 ID 时,我总是得到 nullPointer... 这是我的意图定义的代码:

public static void criaNotification(Context context, CharSequence tickerText, CharSequence title,
                                    CharSequence message, int id, Intent intent){

    Bundle params = new Bundle();

    params.putString("Tipo", "notification");
    params.putInt("id", id);

    intent.putExtras(params);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

这是我尝试检索附加内容的地方,但我总是得到 nullPointer:

Intent intent = getIntent();
final Bundle params = intent.getExtras();

if(params.getString("Tipo").equals("notification")){
    despertador = dbHelp.selectPorId(Integer.parseInt(params.getString("id")));

就是这样...如您所见,我已经尝试在我的 PendingIntent 中使用该标志

【问题讨论】:

  • 你从哪里获取额外的?提供更多关于在何处执行代码第二部分的上下文。因为看起来getIntent() 不是你应该使用的那个。
  • 我正在检索活动...

标签: android android-pendingintent


【解决方案1】:

您使用params.putInt("id", id);,但使用params.getString("id")。使用intString,但不要混合使用。

【讨论】:

  • 对不起,我已经用 putInt 和 String 修复了这个问题,但我总是得到 nullPointer,我不知道发生了什么......我尝试了 putInt,getInt,但我总是得到 1 , 使用 String - String 它总是一个 nullPointer...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-10
  • 2018-12-12
  • 1970-01-01
  • 1970-01-01
  • 2014-09-13
  • 1970-01-01
相关资源
最近更新 更多