1

由于某种原因,我想在应用程序中删除我的 sqlite db:

this.deleteDatabase(contentProvider.getDatabaseName());

之后我想重新创建我的数据库文件。

我在文档中读到:

onCreate is called for all registered content providers on the application main thread at application launch time.

这就是我在启动时在 OnCreate 中创建数据库的方法:

@Override
    public boolean onCreate() {
        try {
            contentProviderHelp = new ContentProviderHelp();

            userInfoTable = new UserInfoTable(contentProviderHelp);
            employeeInfoTable = new EmployeeInfoTable(contentProviderHelp);
            productsTable = new ProductsTable(contentProviderHelp);

            db = new DbMetadata(userInfoTable, employeeInfoTable, productsTable);
            ddlHelp = new DDLHelper(db);

            matcher = new UriMatch(userInfoTable, employeeInfoTable, productsTable, new UriMatcher(UriMatcher.NO_MATCH));

            dbHelp = new DatabaseHelper(getContext(), DATABASE_NAME, DATABASE_VERSION, ddlHelp);
            projectionMaps = new ProjectionHelper(db);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

你能帮我在删除数据库文件后如何重新创建 ContentProvider 吗?

4

1 回答 1

1

只需为这种情况创建一个静态函数DatabaseHelper并提供当前上下文作为参数。在你的DatabaseHelper你可以重新创建数据库

于 2013-07-15T11:40:04.847 回答