何时使用内容提供者 [英] When to use a Content Provider

查看:32
本文介绍了何时使用内容提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解内容提供程序旨在允许在应用程序之间公开共享数据.但是,我想知道是否有人想过让 Content Provider 仅在您自己的应用程序中使用.这样做有什么好处吗?有什么缺点吗?

I understand that Content Providers are made to allow publicly sharing data between applications. However, I'm wondering if anyone has thoughts about making a Content Provider to use just within your own app. Would there be any advantages to doing this? Any disadvantages?

过去我刚刚实现了 SQliteOpenHelper 来访问我的数据库中的数据,但我正在考虑创建一个内容提供者.我觉得请求数据的 URI 方法清晰简洁.另一方面,只为我的应用程序使用 Content Provider 是否是多余的(因为在其中我将有一个 SQliteOpenHelper 类)和比我需要的更多的工作?

In the past I've just implemented the SQliteOpenHelper to access data from my database, but I'm considering creating a Content Provider. I feel like the URI approach to requesting data is clear and concise. On the other hand, will using a Content Provider just for my application be redundant ( since within it I will have a SQliteOpenHelper class ) and more work than I need?

推荐答案

如果您不打算共享数据,请不要考虑 Content Providers.它们功能强大但难以编写,如果您打算在内部使用它们,那么实现它们将是愚蠢的.

If you are not planning to share data, don't think about Content Providers. They are powerful but hard to write and it will be just silly to implement them if you are going to use them internally.

但是,我想知道是否有人想过让 Content Provider 仅在您自己的应用中使用.

However, I'm wondering if anyone has thoughts about making a Content Provider to use just within your own app.

当然...例如,对于我写的一个旧的待办事项列表应用程序,我必须编写一个内容提供程序以允许其他应用程序检索和访问任务状态.这是要求的一部分,但更重要的是它有意义并使应用程序更好.

Of course... for instance, for an old TODO list app I wrote, I had to write a content provider to allow other apps retrieve and access the tasks states. It was part of the requirements, but more than that it made sense and made the app nicer.

这篇关于何时使用内容提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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