android - Realm error: Your Realm is opened from a thread without a Looper and you provided a callback, we need a Handler to invoke your callback -
i've made code in method oncomplete()
of subscriber:
long size, perc; public void oncompleted() { log.wtf("on complete","on complete"); realm = realm.getinstance(defaultconfig); realm.executetransactionasync(new realm.transaction() { @override public void execute(realm mrealm) { airportr airport = new airportr(); size = airp.size(); log.d("size:", string.valueof(size)); (int = 0; < airp.size(); i++) { airport.setid(integer.parseint(airp.get(i).getid())); perc = / size * 100; log.d("i + percentage", string.valueof(i) + " - " + string.valueof(perc)); mrealm.insertorupdate(airport); } } }, new realm.transaction.onsuccess() { @override public void onsuccess() { } }, new realm.transaction.onerror() { public void onerror(throwable error) { error.printstacktrace(); } }); }
and when use debugger, see error message:
java.lang.illegalstateexception: realm opened thread without looper , provided callback, need handler invoke callback
and see if don't use transaction.success()
, transaction.onerror()
works , have problem if use these.
is there way fix it?
thanks
oncompleted()
doesn't seem run on ui thread. normal background thread on scheduler doesn't have looper, realm cannot notify when async transaction complete.
you should either use executetransaction()
because you're on background thread, or run executetransactionasync()
looper thread (for example ui thread).
Comments
Post a Comment