将光标传递给服务

发布于 2024-12-29 04:21:41 字数 231 浏览 2 评论 0原文

我有一个可能很大的列表视图(10k+ 项)。当用户单击列表中的某个项目时,我在需要光标才能访问整个列表的服务中执行操作。由于我无法通过活动中的 Intent 传递光标,因此我只需将所选项目的 id 发送到服务,然后根据此 id 重新查询数据库。但是,由于这是一个包含大量数据的复杂查询,因此可能需要一段时间。将此游标放在可解析类中而不是重新查询数据库会更快吗?然后我可以将 Intent 中的可解析类传递给 Activity。

谢谢

I have a list view that could be potentially large (10k+ items). When the user clicks on an item in the list, I take an action in a Service which needs the cursor for access to the entire list. Since I cant pass the cursor through an Intent from the activity I just send the id of the selected item to the Service then requery the database based off of this id. However, since this is a complex query with a lot of data, it can potentially take a while. Would it be faster to have this cursor in a Parseable class instead of requerying the database? I can then pass the parseable class in an Intent to the Activity.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅唱ヾ落雨殇 2025-01-05 04:21:41

您可以使用游标窗口来打包来自游标的数据。如果您没有执行任何写入操作:

CursorWindow window = new CursorWindow("MY_CURSOR_WINDOW");

cursor.fillWindow(0, window);

intent.putExtra(String name, window);

如果您想要执行写入操作,那么您需要查询并获取游标,因为游标窗口缓存了数据而没有其他任何内容。

http://developer.android.com/reference/android/database/CursorWindow.html干杯

You can use a cursor window to parcel data from a cursor.If you are not doing any write operations:

CursorWindow window = new CursorWindow("MY_CURSOR_WINDOW");

cursor.fillWindow(0, window);

intent.putExtra(String name, window);

In case you want to do write operation then you need to query and get a cursor,since cursorwindow caches the data and nothing else much.

http://developer.android.com/reference/android/database/CursorWindow.html

Cheers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文