Android implementation with Realm DB, transactions on main UI Error
Asked Answered
T

2

6

I am implementing an instance of the Realm Database within the android application I am designing. However, at first I got this error about Realm transactions on main UI thread:

Running transactions on the UI thread has been disabled. It can be enabled by setting 'RealmConfiguration.Builder.allowWritesOnUiThread(true)'.

I enabled the setting mentioned above, but the error persisted. I decided to implement an AsyncTask class in order to try to execute the realm transaction within the doinbackground method (which runs on a separate thread) but i am still getting the same error.

Can you offer me some advice on how I should proceed?

kind regards, Lampros

Triliteral answered 28/11, 2020 at 20:28 Comment(2)
Hi, I am getting the same error and I do not know how to enable that setting at all. Could you help me out?Shaffert
Is there any update? I am also facing the same error.Stans
S
4

Are you actually building a Realm configuration object after you call allowWritesOnUiThread(true) and using it to retrieve your Realm instance?

Splint answered 30/11, 2020 at 8:46 Comment(2)
Yes. After calling allowWritesOnUiThread(true), i am calling .build() also. Still the error showing.Stans
@PrantikMondal did you get any solution?Misfeasance
M
3

I know this is late but was able to resolve this by changing realm.execute to realm.executeTransactionAsync instead of setting allowWritesOnUiThread(true).

Micamicaela answered 8/4, 2022 at 18:16 Comment(1)
Thank you, this solution was more helpful comparatively.Volans

© 2022 - 2024 — McMap. All rights reserved.