1.问题
为什么在接收到推送通知的回调onNotification,onMessage,onNotificationOpened中无法打开activity?
2.解决方案
上述回调中的context参数为ApplicationContext,使用ApplicationContext实现页面跳转时需要设置Intent.INTENT_FLAG_NEW_TASK标志位。可参考以下代码:
- [backcolor=transparent]@Override
- [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]{
- [backcolor=transparent] [backcolor=transparent]......
- [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]);
- [backcolor=transparent] intent[backcolor=transparent].[backcolor=transparent]addFlags[backcolor=transparent]([backcolor=transparent]Intent[backcolor=transparent].[backcolor=transparent]FLAG_ACTIVITY_NEW_TASK[backcolor=transparent]);
- [backcolor=transparent] context[backcolor=transparent].[backcolor=transparent]startActivity[backcolor=transparent]([backcolor=transparent]intent[backcolor=transparent]);
- [backcolor=transparent]}