0
我目前使用realm查詢RealmObjects以在GoogleMap上顯示它們。我正在執行讀取並獲取RealmResults,但我無法找到從UI線程將標記放在地圖上的方法。我更喜歡用異步調用來做到這一點,因爲它會在UI線程上產生〜150ms的延遲。Realm Android:Async Transaction影響UI線程
public void loadLocations(final GoogleMap googleMap) {
try {
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmResults<LocationObject> locations = realm.where(LocationObject.class).findAll();
for (LocationObject location: locations) {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(location.lat, location.long))
}
}
});
}
如何在以後訪問UI線程上的RealmResults? Realm提到RealmObjects受線程限制
Ohhhhh所以當初始的「findAllAsync」事務完成時以及之後的每次更新都會調用更改偵聽器。很好的建議,謝謝@andyaldoo –
@JesusGarcia確實如此。 –