我想使用Service类中的LiveData选择Room数据库上的数据。当观察它时,如何将LifecycleOwner强制转换为正确类型?
repositoryDatabase.getTimeline().observe(this, timelineList -> {
if (timelineList != null && timelineList.size() >= 10) {
JSONArray arrayTimeline = new JSONArray();
for (TimelineEntity timeline : timelineList) {
JSONObject objectTimeline = new JSONObject();
try {
objectTimeline.put("doku", timeline.getIdDokumen());
objectTimeline.put("entrydate", timeline.getEntryDate());
objectTimeline.put("lat", timeline.getLat());
objectTimeline.put("lng", timeline.getLng());
arrayTimeline.put(objectTimeline);
} catch (JSONException e) {
e.printStackTrace();
}
}
onUpdateLocation(arrayTimeline.toString());
}
});