由于某种原因,我想在应用程序中删除我的sqlite数据库:
this.deleteDatabase(contentProvider.getDatabaseName());
之后我想重新创建我的数据库文件。
我在documentation中读到了:
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的问题?
答案 0 :(得分:1)
在这种情况下,只需在DatabaseHelper
中创建一个静态函数,并将当前上下文作为参数提供。在DatabaseHelper
中,您可以重新创建数据库