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

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

问题描述

据我所知,内容提供商都是为了让应用程序之间公开共享数据。不过,我想知道如果任何人有有关使内容提供商,只是在自己的应用程序中使用的想法。会不会有任何优势,这样做呢?任何缺点?

在过去,我只是实现了SQliteOpenHelper从我的数据库访问数据,但我正在考虑创建一个内容提供商。我觉得像URI的方式来请求数据简洁明了。在另一方面,将通过内容提供商只是为我的应用程序是多余的(因为在它里面,我将有一个SQliteOpenHelper类)和更多的工作比我更需要?

解决方案

如果您不打算共享的数据,不考虑内容提供商。他们是强大的,但很难写,这将是多么愚蠢的实现他们,如果你要在内部使用它们。

  
    

不过,我想知道如果任何人有有关使内容提供商,只是在自己的应用程序中使用的想法。

  

当然...例如,对于一个老待办事项列表应用程序,我写的,我不得不写一个内容提供商,以允许其他应用程序检索和访问任务状态。这是要求的一部分,但比它有意义,并提出了应用程序更好了。

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?

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?

解决方案

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.

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天全站免登陆