Android Kotlin Realm Proper Way of Query+ Return Unmanaged Items on Bg Thread

后端 未结 1 1599
孤独总比滥情好
孤独总比滥情好 2021-01-15 18:24

What is the proper way of querying and returning an unmanaged result of items with realm, everything in the background thread?. I\'m using somethibf like this:



        
相关标签:
1条回答
  • 2021-01-15 18:44

    This is how you would turn your Realm objects unmanaged:

        return Observable.defer(() -> {
            try(Realm realm = Realm.getDefaultInstance()) {
                return Observable.just(
                    realm.copyFromRealm(
                        realm.where(ItemRealm.class).equalTo("sent", false).findAll()
                    )
                );
            }
        }).subscribeOn(Schedulers.io());
    

    Although this answer is Java, the Kotlin answer is just half step away.

    0 讨论(0)
提交回复
热议问题