how to decide between direct database access and content provider?

前端 未结 3 1207
时光取名叫无心
时光取名叫无心 2020-12-29 08:15

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

3条回答
  •  心在旅途
    2020-12-29 08:36

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

    Pros:

    • 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).

    Cons:

    • Can be confusing if you don't have a good example handy.
    • If you have an enterprise Java background, ORM might be more familiar.

    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.

提交回复
热议问题