android - 如何在自定义 ArrayList 中保存 FCM 通知?
问题描述
我正在尝试将自定义 Arraylist 保存在共享首选项中,但是当我重新启动或重新运行并发送新推送时,它会覆盖其他
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
NotificationData data = new NotificationData(remoteMessage.getData());
notificationDataArray.add(data);
SharedPreferences sharedPreferences = getSharedPreferences(NotificationShared.SHARED_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
Gson gson = new Gson();
String json = gson.toJson(notificationDataArray);
editor.putString(NotificationShared.DATA_ARRAY, json);
editor.apply();
}
解决方案
您不应将 Notification 中的数据保存在自定义 ArrayList 中,而应将数据保存到 SQLite 数据库中
推荐阅读
- javascript - 由于recaptcha,需要按两次提交按钮
- asp.net - 如何在剑道网格中隐藏密码
- mysql - 如何按 MySQL 中第 2 列中的值的顺序获取第 1 列中的值总数
- python - 您可以在协程列表上使用多处理或线程来加速程序执行吗?
- wordpress - wordpress 添加支付系统。在哪里处理表格
- r - 有没有办法将 cld 添加到组合的 ggplot 中?
- javascript - 如何使用此服务器响应访问嵌套的 JSON 对象
- javascript - 修复了在折叠视图中切换时 CSS 导航栏消失的问题
- node.js - 在高流量期间阻塞 ClientRead 上的空闲连接以进行参数化查询(绑定)
- java - DCEVM 安装不成功 - JVM_CopySwapMemory 错误(在 jvm.dll 中找不到)