如何直接访问数据库和内容提供商之间做出选择? [英] how to decide between direct database access and content provider?

查看:144
本文介绍了如何直接访问数据库和内容提供商之间做出选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写,由业务逻辑和UI部分的应用程序。有数据的存储和访问/双方BL和用户界面的修改比较大的量。在大多数的情况下改变所存储的数据应该由UI立即反映。

I am writing an application that consists of business logic and UI parts. There is quite big amount of data to be stored and accessed/modified by both BL and UI. In most of the cases changes to the stored data should be reflected by UI immediately.

我该如何决定是否应该或不应该使用直接数据库访问?内容提供商?

How do I decide whether I should or should not use direct DB access? content provider?

我已经做了一些关于这个问题的阅读( 1 ,<一个href="http://stackoverflow.com/questions/3350408/exact-difference-between-content-provider-and-sqlite-database">2)我理解这两个选项之间的区别。

I have done some reading on the subject (1, 2) and I understand the difference between these two options.

请其他方面的问题,如性能,code开发和可维护性等难度分享您的想法。

Please share your thoughts on other aspects of the problem, such as performance, difficulty level of code development and maintainability, etc.

推荐答案

在我写的应用程序,我发现,一旦你过去的学习曲线,实现ContentProvider的是pretty的方便。

In the apps that I've written, I've found that once you get past the learning curve, implementing a ContentProvider is pretty easy.

优点

  • 在没有外部的依赖关系。
  • 在数据库连接的生命周期是由ContentProvider的处理。
  • 轻松传递一个Intent活动的内容的URI。
  • 通过CursorLoader
  • 在简单的背景查询(或推出自己的)。
  • No external dependencies.
  • DB connection lifecycle is handled by the ContentProvider.
  • Easily pass content URIs between Activities in an Intent.
  • Simple background queries via CursorLoader (or roll your own).

缺点

  • 在可能会造成混淆,如果你没有一个很好的例子方便。
  • 如果你有一个企业级Java的背景下,ORM可能会更熟悉。

当我试图找出如何实现ContentProvider的,我在倒在例如code谷歌的I / O 应用。在你做决定,我想至少花一天时间原型之一,所以你可以权衡的第一手经验。

When I was trying to figure out how to implement a ContentProvider, I poured over the example code in Google's I/O application. Before you make a decision, I would at least spend a day prototyping one so you can get first-hand experience of the tradeoffs.

这篇关于如何直接访问数据库和内容提供商之间做出选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆