【问题标题】:Lost extras where starting Activity by click on Notification (PendingIntent)通过单击通知(PendingIntent)启动活动时丢失的附加信息
【发布时间】:2017-07-13 10:38:53
【问题描述】:

我有接收推送通知的应用程序。这些推送通知包含有效负载。收到此通知后,我会解析这些有效负载并将其作为Bundle 添加到packageIntent

Intent packageIntent = context.getPackageManager().
        getLaunchIntentForPackage(Constants.PUSH_PACKAGE_NAME);
// putting bundle
packageIntent.putExtras(extras);
packageIntent.setAction(Long.toString(System.currentTimeMillis()));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, packageIntent,
        PendingIntent.FLAG_UPDATE_CURRENT);

最后我将PendingIntent 作为“内容意图”添加到Notification

builder.setContentIntent(pendingIntent);

但是当我点击收到的Notification 时,打开的Activity 在其getIntent().getExtras() 上有一个空的Bundle。为什么会丢失?

【问题讨论】:

  • 请发布您的清单。当您点击通知时,您的Activity 是否已经打开? Bundle 中是否有任何自定义对象,还是像 intString 这样的普通对象?

标签: android android-notifications android-pendingintent


【解决方案1】:

尝试使用PendingIntent.FLAG_ONE_SHOT 代替PendingIntent. FLAG_UPDATE_CURRENT 并在AndroidManifest.xml文件中的应用程序标签中检查android:allowBackup="true"

【讨论】:

  • 使用不同的PendingIntent 标志将一无所获。 allowBackup 和这个问题有什么关系?为什么这会得到支持?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-31
  • 1970-01-01
  • 2012-04-28
相关资源
最近更新 更多