如何实现境界的android以下如何实现、境界、android

2023-09-06 14:48:45 作者:恶魔由我主宰

在我的应用程序,我通常有一个加载器加载从sqlite的数据,然后将其传递到任何活动或片段被连接,从那里的absListView的适配器设置,然后presents它给用户

In my applications, I usually have a loader that loads the data from sqlite and then passes it on to either the activity or fragment it is attached, from where it is set in the adapter of a absListView which then presents it to the user

由于境界指出,其对象不应该跨线程共享< /一>,这可怎么未做从UI线程中的任何数据库调用实现? (这将使应用程序感觉迟钝,因为我打的分贝量好)

Since realm states that its objects shouldn't be shared across threads, how can this be achieved without making any db calls from the UI thread? (which would make the app feel sluggish as I hit the db a good amount)

另外,在3 范例 - 的介绍,的 GridView控件和放大器; 迁移,许多次数据库操作都在UI线程中完成的。在UI线程没有数据库操作的Andr​​oid巨资皱起了眉头?

Also in the 3 examples - intro, gridView & migration, a number of times db operations are done in the UI thread. Isn't database operations in UI thread heavily frowned in Android?

从文档报价 - 可能长时间运行的操作,例如网络或数据库操作,或者计算昂贵计算,例如调整大小位图应在工作线程(通过异步请求或在数据库中操作的情况下,)来完成。的

推荐答案

你是对的,但目前无法加载在后台线程的项目,然后将其解析到UI线程。这是路线图然而,在这里看到: https://github.com/realm/realm -java /问题/ 503

You are right, currently it is not possible to load items on a background thread and then parse it to the UI thread. It is on the roadmap however, see here: https://github.com/realm/realm-java/issues/503

境界是pretty的,虽然速度快,所以在此之前,对于较小的数据,你可能不会跳帧,即使你加载UI线程上的数据。

Realm is pretty fast though, so until then, for smaller amounts of data you would probably not skip frames even though you load data on the UI thread.