Obtaining contacts from content provider without duplicates or invalid contacts, and save to Realm

自古美人都是妖i 提交于 2019-12-04 16:28:00

Okay, after quite long searching I found that there was a typo:

        /** merge mechanism */
        realm.where(Contact.class)
                .equalTo("isBeingSaved", false)
                .findAll()
                .deleteAllFromRealm(); // delete all non-saved data
        for(Contact contact : realm.where(Contact.class).findAll()) {
            realmContact.setIsBeingSaved(false); <- here it is
        }

It's realmContact when in fact it should be contact so it refers to contact iterated by for loop.

So, basically, it was setting Contact realmContact = new Contact(); to false. So the proper version is:

           /** merge mechanism */
            realm.where(Contact.class)
                    .equalTo("isBeingSaved", false)
                    .findAll()
                    .deleteAllFromRealm(); // delete all non-saved data
            for(Contact contact : realm.where(Contact.class).findAll()) {
                contact.setIsBeingSaved(false);
            }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!