2

是否可以在应用程序中初始化 contentprovider?

因为我需要为每个用户/服务器组合创建一个数据库,并且我正在使用 contentprovider 的 oncreate 方法中的登录信息创建数据库!

4

2 回答 2

1

Based on what it sounds like you are trying to do, you may consider contextualizing your ContentProvider's database access (this may be another way of describing what @Gary B. was getting at):

When you initialize the content provider, create a database within which you will store the list of user/server combinations. Then, when a user logs into the application, create the corresponding database and update the master list for the ContentProvider.

In the ContentProvider's public operations, determine which user/server combination is active (or being requested) and then look up the appropriate database in the master database you created on installation. You can then read the user/server specific information and return this to the caller.

Alternatively, you could likely implement this all within one database, but I don't understand enough about your requirements to recommend a specific approach...

于 2011-08-31T21:29:05.483 回答
0

SQLiteOpenHelper通常是创建数据库的地方。更具体的onCreate(SQLiteDatabase)方法。安装应用程序时,它将创建数据库。

于 2011-08-31T08:34:07.103 回答