简体   繁体   English

Android通过单个光标获取多个内容提供程序

[英]Android get multiple content Provider with single cursor

Hello Everyone , I am creating an application in which I have to deal with multiple content providers. 大家好,我正在创建一个必须与多个内容提供者打交道的应用程序。 To get every content I have to create a cursor. 要获取所有内容,我必须创建一个游标。 For example I create a cursor to get phone contacts and then create another to get call logs etc.I wonder is this necessary to create a new cursor every time to get a content.I want to know is there any way to get multiple contents with single cursor so that my code will be shorten. 例如,我创建一个游标以获取电话联系,然后创建另一个以获取通话记录等。我想知道是否有必要每次都创建一个新游标以获取内容。我想知道有什么方法可以用单光标,这样我的代码就会缩短。 Thanks in advance 提前致谢

It is not possible, and even if it was, that's not the way to go. 这是不可能的,即使是那样,这也不是可行的方法。 Imagine you got a Database with multiple tables: customers, sales, products; 假设您有一个包含多个表的数据库:客户,销售,产品; and each time you ask for customers, it brings you sales and products too. 每次您要客户时,也会带来销售和产品。 Not so efficient, right? 效率不高吧?

The correct way to go is use 1 Cursor for each data set you need. 正确的方法是为所需的每个数据集使用1个Cursor

PS: also always remember that shorter code != better. PS:还请记住,较短的代码!=更好。 Easy maintainable code == better. 易于维护的代码==更好。 That is called Scalability . 那就是可伸缩性 Read more here . 在这里阅读更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM