在我的应用程序中,我读取了保存在手机上的联系人,这可能需要很长时间,然后我把它放在Thread
嵌套,我使用Realm
,但我得到这个错误:Android我怎样才能在线程上使用Realm
Realm access from incorrect thread.
Realm objects can only be accessed on the thread they were created.
而我的解决方案不解决这个问题,比如:
new Handler().post(new Runnable() {
@Override
public void run() {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
}
});
}
});
OR
new Handler(getMainLooper()).post(new Runnable() {
@Override
public void run() {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
}
});
}
});
嵌套线程,
您对我的博文的回答非常有用,比最新接受的博文更好,非常感谢 –
为什么我会在此答案中做线程跳转?这很奇怪。 – EpicPandaForce