私人内容提供商有什么用?
Android 开发指南 说
内容提供商对于 读取和写入数据 对您的应用程序来说是私有的,而不是 已分享。
通常,内容提供者用于向不同的应用程序提供数据或在它们之间共享数据。我想知道拥有私人提供商并且不想共享它是否有任何用处。是否有直接访问数据库或文件系统无法提供的好处?
谢谢, 拉贾特
The Android Dev Guide says
Content providers are also useful for
reading and writing data that is
private to your application and not
shared.
Generally, Content Providers are used for providing data to different applications or sharing data among them. I was wondering if there is any use to having private providers and not wanting to share it. Are there any benefits provided that a direct access to DB or file system don't provide?
Thanks,
Rajath
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CursorLoader
),以确保您的应用程序在 UI 端顺利运行。ContentProvider
访问的任何线程的可重入数据库访问。 code>,这样所有锁定都可以完全发生在您的 ContentProvider 覆盖调用中,而不是在数据库层、服务和 UI 层中跟踪它。至于数据库的可重入锁定,它并没有完全做到这一点,但它有所帮助——您的 ContentProvider 类实现了四个简单的函数(CRUD 接口),如果您选择覆盖它,则还可以实现第五个,batchAdd() - - 这会本地化您的锁定。最简单的答案是简单地在函数级别将所有四个/五个函数声明标记为“同步”,然后就完成了。比尝试找出锁定 5 个不同活动中访问数据库的 20 个位置要干净得多。
CursorLoader
) to ensure that your application runs smoothly on the UI sideContentProvider
, so that all locking can happen entirely in your ContentProvider override calls, rather than keeping track of it in a DB layer, a service, and a UI layer.As for re-entrant locking of the DB, it doesn't do it completely, but it helps -- your ContentProvider class implements four simple functions (CRUD interface) and, if you choose to override it, a fifth, batchAdd() -- This localizes your locking. The bone simple answer is to simply tag all four/five of those function declarations "synchronized" at the function level and you're done. Much cleaner than trying to figure out locking out from 20 places that access your DB in 5 different Activites.
例如,多进程应用程序使用场景(如:音乐播放服务通常运行在远程进程中),在一个应用程序中共享数据库的两个进程之间应该使用私有ContentProvider。
For example,a multiprocess application use scenario(like: music play service usually run in a remote process), between the two process that in one application share database should use private ContentProvider.