我们如何在ROOM数据库arrayList
或observeForever()
方法中绑定observe()
notificationModelArrayList = new ArrayList<>();
NotificationRepository notificationRepository = new NotificationRepository(getApplicationContext());
notificationRepository.getAllNotification().observe(NotificationActivity.this,new Observer<List<Notification>>() {
@Override
public void onChanged(@Nullable List<Notification> notifications) {
for (org.jembi.careconekta.dbTables.Notification notification : notifications) {
System.out.println("-----------------------");
System.out.println(notification.getTitle());
System.out.println(notification.getMessage());
NotificationModel notificationModel = new NotificationModel();
notificationModel.setNotificationMsg(notification.getMessage());
notificationModelArrayList.add(notificationModel);
}
}
});
System.out.println
可以正常工作,但是notificationModel
中没有添加notificationModelArrayList