如何在自定义 ArrayList 中保存 FCM 通知?
How to save FCM notification in a custom 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();
}
您不应将通知中的数据保存在自定义 ArrayList 中,而应将数据保存到 SQLite 数据库中
我正在尝试在共享首选项中保存自定义数组列表,但是当我重新启动或重新运行并发送新推送时,它会覆盖其他
@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();
}
您不应将通知中的数据保存在自定义 ArrayList 中,而应将数据保存到 SQLite 数据库中