android - 如何在 Android 应用程序中显示来自推送通知的数据
问题描述
我有一个使用 FCM 推送通知的 android 应用程序。有一个发送推送通知的后端
每次用户上传图片时,都会向订阅该主题的人发送推送通知。
单击通知托盘中的通知后,我将被重定向到应用程序的第一页。
我怎样才能让推送通知像 Instagram 那样工作。
收到通知并单击它后,我想移至该特定屏幕并查看已上传的图像。
如果通知到达时用户在应用程序中。如何刷新活动以显示内容。我是否必须发出后端请求才能显示新数据,还是可以显示通知本身的内容?
有没有我可以看的例子。
任何帮助将不胜感激。谢谢你。
解决方案
要启动一个包含一系列活动的活动,您需要创建一个 TaskStackBuilder 实例并调用 addNextIntentWithParentStack(),将要启动的活动的 Intent 传递给它。
只要您如上所述为每个活动定义了父活动,就可以调用 getPendingIntent() 来接收包含整个后退堆栈的 PendingIntent。
// Create an Intent for the activity you want to start
Intent resultIntent = new Intent(this, ResultActivity.class);
// Create the TaskStackBuilder and add the intent, which inflates the back
stack
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntentWithParentStack(resultIntent);
// Get the PendingIntent containing the entire back stack
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
推荐阅读
- python - 使用 numpy 创建一个十进制数范围不起作用
- css - 在矩形 div 内创建响应式 Square div
- javascript - 更改站点路径而不重新加载站点
- r - 根据进一步向上的行改变新行。尝试使用类似 dplyr::mutate 但跨行的东西
- gradle - minecraft forge gradle“runClient”异常
- r - 数据组编号
- angular - 如何更改角度 Kendo Grid 中的默认过滤器运算符
- java - Idea Intellij 删除了我在 src/main IIIIII 中的所有文件
- plsql-package - for-loop 不适用于 select 语句中的以下记录类型变量
- wpf - 如何在 menuitem WPF 中添加快捷键