我试图将自定义的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();
}