SQLiteOpenHelper VS的ContentProvider [英] SQLiteOpenHelper vs ContentProvider

查看:203
本文介绍了SQLiteOpenHelper VS的ContentProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid的发展。我试图创建一个读取内部数据库(SQLite的)应用程序,并列出所有数据的列表(我使用的ListView )。

到目前为止,我有一类叫做数据库处理器扩展 SQLiteOpenHelper 和正在做的所有数据库操作(选择数据,插入数据,删除数据,...)。

但现在,我想列出的值,我读的一些网站,我必须使用装载机而不是光标,并因此的ContentProvider 。到目前为止,据我所知,的ContentProvider 提供对数据库控制的访问。

我的问题是:是否在的ContentProvider 做同样的 SQLiteOpenHelper

另外,我使用的API级别8和的ContentProvider 仅适用于API级别11.什么是解决这一问题的最佳方法是什么?

在此先感谢。

解决方案
  

我的问题是:在ContentProvider的做同样的   SQLiteOpenHelper?

的ContentProvider 是由应用程序的开发实施,如果他或她会允许其他开发人员能够访问应用程序的数据库在自己的应用程序 - 简单地把对的共享的。这就像一些数据库的服务器和它的客户端 ContentResolver的谁知道的ContentProvider 的权威。例如,如果你需要得到一些接触,从您的设备,比你应该使用的ContentProvider 联系人数据库,更具体地是的合同类的。

如果您知道相应的 ContentProvider的权威你可以用它使用 ContentResolver的对象的comunicate。

在其他情况下,你应该使用数据库通过SQL抽象模型,重新由<一个psented $ P $互动href="http://developer.android.com/reference/android/database/package-summary.html"><$c$c>android.database和<一href="http://developer.android.com/reference/android/database/sqlite/package-summary.html"><$c$c>android.database.sqlite类。

和也。 - 的ContentProvider 可从主AP​​I级别为应用程序的主要成分之一

更新

从官方文档:

  

在你开始建立一个供应商,请执行以下操作:

     
    

确定是否需要内容提供商。你需要建立一个内容     供应商如果要提供以下一个或多个功能:

         

  • 您想提供复杂的数据或文件到其他应用程序。     
  • 您希望允许用户从您的应用程序复制复杂的数据到其他应用程序。     
  • 您想使用搜索框架提供自定义的搜索建议。

      
  • I'm new to Android development. I'm trying to create an application that reads from the internal database (SQLite) and list all the data in a list (I'm using listView).

    So far I got a class called DatabaseHandler that extends SQLiteOpenHelper and that is doing all the database operations (select data, insert data, delete data, ...).

    But now that I want to list the values, I am reading in some websites that I have to use a Loader instead of Cursor, and therefore a ContentProvider. So far I understand that ContentProvider provides controlled access to the database.

    My question is: does the ContentProvider do the same as SQLiteOpenHelper?

    Also, I'm using API level 8 and the ContentProvider is only available on API level 11. What is the best way to solve this?

    Thanks in advance.

    解决方案

    My question is: does the ContentProvider do the same as SQLiteOpenHelper?

    ContentProvider is implemented by application's developer if he or she would allow other developers to access to application's database in their application - simply put for sharing. It's like a server of some database and it's client is ContentResolver who knows ContentProvider's authority. For example if you need to get some contacts from your device, than you should use ContentProvider of Contacts database and more concretely it's Contract classes.

    If you know an authority of appropriate ContentProvider you may comunicate with it using a ContentResolver object.

    In other cases you should interact with database through SQL abstract model which is represented by android.database and android.database.sqlite classes.

    And also - ContentProvider available from the primary API level as one of the main component of application.

    Update

    From the official documentation:

    Before you start building a provider, do the following:

    Decide if you need a content provider. You need to build a content provider if you want to provide one or more of the following features:

  • You want to offer complex data or files to other applications.
  • You want to allow users to copy complex data from your app into other apps.
  • You want to provide custom search suggestions using the search framework.

  • 这篇关于SQLiteOpenHelper VS的ContentProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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