in Education by
This question is often asked and resolved in many ways, but if I come back to the same question, it's because I'm a bit confused. This is my first time to deal with Realm ORM. This repository class state for the implementation on db storage. Its take instance of Realm and ApiService class LoginRepositoryImpl(var realm: Realm, var apiService: ApiService){ override fun doLogin(email: String, password: String) { apiService.loginCheck(email, password) .flatMap { t: EntityToken -> // check if user already exist and delete it val checkIfUserExist = getUserIfExist("email", email) if (checkIfUserExist != null) { realm.executeTransactionAsync { checkIfUserExist.deleteFromRealm() } } // insert user into DB realm.executeTransactionAsync { bgRealm -> val user = bgRealm.createObject(UserModel::class.java, UserModel.cachedNextId) user.email = email user.logged = true } // i want to make another request to server return@flatMap apiService.pingServer(t.refresh_token) } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ uR -> // make update of user table realm.executeTransactionAsync { getUserIfExist("email", email)?.fullname = uR.fullname } } } //function to check if user instance already exist private fun getUserIfExist(field: String, email: String): UserModel? { return realm.where(UserModel::class.java) .equalTo(field, email) .findFirstAsync() } } Ps.help me to resolve Realm access from incorrect thread JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can create wrapper over realm that will use Schedulers.single(). It will use the same thread everytime. But I think I had to get Realm instance from that thread too. I did it the ugly way public long count() throws RealmException { return Single.fromCallable(() -> realmService.getRealm().where(dataTypeClass).count()) .subscribeOn(Schedulers.single()) .blockingGet(); } realmService.getRealm() returns Realm instance that is lazily loaded only once. You can also just return Single and chain calls using RxJava.

Related questions

0 votes
    I'm looking for a general solution for upgrading database schema with ORM tools, like JPOX or Hibernate. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 26, 2022 in Education by JackTerrance
0 votes
    I'm looking for a general solution for upgrading database schema with ORM tools, like JPOX or Hibernate. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 9, 2022 in Education by JackTerrance
0 votes
    How would you deal with slow application complaint from clients?...
asked Jun 11, 2021 in Technology by JackTerrance
0 votes
    I have a number of user permissions that are tested throughout my ASP.NET application. These permission ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Previous version of Retrofit uses RestAdapter and has provision of enabling the Logs. Why that feature is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: RxJava delay for each item of list emitted (17 answers) Closed 5 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    Let's say you have a typical web app and with a file configuration.whatever. Every developer working on ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Can you relate of an experience when you found your colleagues code to be inefficient? How did you deal with it?...
asked Jun 13, 2021 in Education by Editorial Staff
0 votes
    You are given a data set consisting of variables with more than 30 percent missing values. How will you deal with them?...
asked Apr 26, 2021 in Technology by JackTerrance
0 votes
0 votes
    I am getting memory leak during migration using Realm (v1.0.2). My code looks like that: let ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I am creating an application for Android. I am using Realm as a Database. Realm working fine in the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I am using Realm with Swift 3 in my iOS app. I have the following code //Find all records for the day func ... { let predicate = NSPredicate(format: "date >= %@ and date...
asked May 8, 2022 in Education by JackTerrance
0 votes
    Point-of-sale intrusion does not deal with financial details and credit card information. (a) True (b) False This ... Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 4, 2021 in Education by JackTerrance
...