java - Realm synchronous writes from intent service -


i'm using realm database , intent service , ui, since part of library can't call or set default of realm, retrieve realm using realm.getinstance(config) every intent, , because can't reuse realm not knowing thread i'll running on cannot use asynchronous writes.

as such getting following error each time write record

"mixing asynchronous queries local writes should avoided. realm convert async queries synchronous in order remain consistent. use asynchronous writes instead."

i'm assuming "local writes" author means "synchronous"?

from understanding of realm utilization in scenario don't believe there alternative?

am correct in understanding proper way write object intent service scenario is:

realm realm = getnewrealminstance(); try {   realm.begintransaction();   record newrecord = new record().setfield1(x).setfield2(y);   realm.copytorealm(newrecord);   realm.committransaction(); } catch (throwable error) {   realm.canceltransaction(); } {   realm.close(); } 

?

in addition getting following log messages (with no exceptions thrown)

e/realm_jni: jni: throwingexception 7, std::exception in /users/zaki/fromgit/realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_tablequery.cpp line 1285, . e/realm_jni: exception has been throw: std::exception in /users/zaki/fromgit/realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_tablequery.cpp line 1285 

"mixing asynchronous queries local writes should avoided. realm convert async queries synchronous in order remain consistent. use asynchronous writes instead."

you warning if execute synchronous writes on ui thread. surely can ensure don't write on ui thread?


this works intent service :

 realm realm = getnewrealminstance();  try {        realm.executetransaction(new realm.transaction() {             public void execute(realm realm) {                 record newrecord = new record().setfield1(x).setfield2(y);                 realm.insert(newrecord);             }         });  } {        realm.close();  } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -