{"action":"closed","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/4157","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/4157/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/4157/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/4157/events","html_url":"https://github.com/realm/realm-java/issues/4157","id":206194821,"number":4157,"title":"error Realm access from incorrect thread","user":{"login":"poly-sb","id":24455355,"avatar_url":"https://avatars.githubusercontent.com/u/24455355?v=3","gravatar_id":"","url":"https://api.github.com/users/poly-sb","html_url":"https://github.com/poly-sb","followers_url":"https://api.github.com/users/poly-sb/followers","following_url":"https://api.github.com/users/poly-sb/following{/other_user}","gists_url":"https://api.github.com/users/poly-sb/gists{/gist_id}","starred_url":"https://api.github.com/users/poly-sb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poly-sb/subscriptions","organizations_url":"https://api.github.com/users/poly-sb/orgs","repos_url":"https://api.github.com/users/poly-sb/repos","events_url":"https://api.github.com/users/poly-sb/events{/privacy}","received_events_url":"https://api.github.com/users/poly-sb/received_events","type":"User","site_admin":false},"labels":[{"id":3545600,"url":"https://api.github.com/repos/realm/realm-java/labels/T:Help","name":"T:Help","color":"cc317c","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-02-08T13:14:49Z","updated_at":"2017-02-08T14:17:57Z","closed_at":"2017-02-08T14:17:57Z","body":"I cannot figure out why this code give me a 'error Realm access from incorrect thread'.\r\n\r\nI instantiated my dao on the main thread of my BaseActivity.\r\n```java\r\nprotected Dao dao;\r\n\r\n@Override\r\nprotected void onCreate(@Nullable Bundle savedInstanceState) {\r\n    super.onCreate(savedInstanceState);\r\n    dao = new Dao();\r\n}\r\n```\r\n\r\nHere the body of my dao:\r\n```java\r\nprivate Realm realm;\r\n\r\npublic Dao() {\r\n    realm = Realm.getDefaultInstance();\r\n}\r\n\r\npublic void removeEntity(Long id) {\r\n     realm.executeTransactionAsync((r) -> {\r\n         TaskEntity t = r.where(TaskEntity.class).equalTo(MyEntity.ID, id).findFirst();\r\n         t.deleteFromRealm();\r\n     });\r\n}\r\n```\r\n\r\nOn my child activity I use the instance from my BaseActivity to persist my entity.\r\n```java\r\n@Override\r\npublic void onWebSocketMessage(String id) {\r\n    runOnUiThread(()->{\r\n        dao.removeEntity(Long.valueOf(id))\r\n    });\r\n}\r\n\r\n```\r\nRealm version: io.realm:realm-gradle-plugin:2.2.1\r\nRealm sync feature enabled: no\r\nAndroid Studio version: 2.2.2\r\n\r\n"}}
{"actor":{"display_login":"poly-sb"}}