【发布时间】:2017-09-01 14:31:00
【问题描述】:
我不断得到:
java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created.
但是线程在它甚至触及领域对象时就被中断了,我有什么办法解决这个问题吗?
RealmConfiguration config = new RealmConfiguration.Builder()
.name("CustomSchedule.realm")
.schemaVersion(42)
.build();
mRealm = Realm.getInstance(config);
mDays = app.getmDays();
final Handler handler = new Handler();
t = new Thread(new Runnable() {
public void run() {
while(!Thread.currentThread().isInterrupted()) {
while (mDays.isEmpty()) {
}
Thread.currentThread().interrupt();
startActivity();
handler.post(this);
}
}
});
t.start();
return rootView;
}
在 startActivity 部分中,我照常引用领域对象。
【问题讨论】:
标签: android multithreading event-handling realm