开发者社区> 问答> 正文

移动推送Android SDK:在通知回调中无法打开activity,这是怎么回事?



1.问题


为什么在接收到推送通知的回调onNotification,onMessage,onNotificationOpened中无法打开activity?

2.解决方案


上述回调中的context参数为ApplicationContext,使用ApplicationContext实现页面跳转时需要设置Intent.INTENT_FLAG_NEW_TASK标志位。可参考以下代码:

  1. [backcolor=transparent]@Override
  2. [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] onNotification[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] title[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] summary[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]Map[backcolor=transparent]<[backcolor=transparent]String[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent]>[backcolor=transparent] extraMap[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  3. [backcolor=transparent]    [backcolor=transparent]......
  4. [backcolor=transparent]    [backcolor=transparent]Intent[backcolor=transparent] intent [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]Intent[backcolor=transparent]([backcolor=transparent]context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]MyActivity[backcolor=transparent].[backcolor=transparent]class[backcolor=transparent]);
  5. [backcolor=transparent]    intent[backcolor=transparent].[backcolor=transparent]addFlags[backcolor=transparent]([backcolor=transparent]Intent[backcolor=transparent].[backcolor=transparent]FLAG_ACTIVITY_NEW_TASK[backcolor=transparent]);
  6. [backcolor=transparent]    context[backcolor=transparent].[backcolor=transparent]startActivity[backcolor=transparent]([backcolor=transparent]intent[backcolor=transparent]);
  7. [backcolor=transparent]}

展开
收起
猫饭先生 2017-10-23 14:17:21 1529 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载