刷新自定义的ContentProvider /重装数据库引用还原后 [英] Refresh/Reload database reference in custom ContentProvider after restore

查看:287
本文介绍了刷新自定义的ContentProvider /重装数据库引用还原后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序使用ContentProvider的,一切的伟大工程,除了一个小问题。我有一个备份和恢复功能的数据库备份到SD卡上的文件,然后将这些备份文件可以恢复到覆盖当前的数据库。这整个过程是工作,但ContentProvider的仍占据参考/缓存原始数据库,一旦旧的备份文件中的一个被恢复。我似乎无法找到一个方法来刷新或重新加载在ContentProvider数据库引用。我知道恢复的作品,因为我可以看到在使用SQLite编辑数据库中的记录,当我关闭并重新打开应用程序,它会显示正确的记录。

I use a ContentProvider in my app and everything works great except for one little issue. I have a backup and restore function that backs up the database to a file on the SD card and then those backup files can be restored to overwrite the current database. This whole process is working, but the ContentProvider still holds the reference/cache to the original database once one of the old backup files is restored. I can't seem to find a way to refresh or reload the database reference in the ContentProvider. I know the restore works because I can see the records in the db with SQLite Editor and when I close and re-open the app, it displays the correct records.

有谁知道一个办法做到这一点?有没有一种方法来关闭并重新打开,我没有看到的ContentProvider的?

Does anybody know a way to do this? Is there a way to close and re-open the ContentProvider that I'm not seeing?

推荐答案

您保持一个引用到实际 SQLiteDatabase 在你的内容提供商(类似呼叫 SQLiteOpenHelper.getWritableDatabase()的onCreate(),然后保持该引用)?或者你从什么地方得到的数据库对象就像在每个提供方法的帮手?

Are you maintaining a reference to the actual SQLiteDatabase in your content provider (something like calling SQLiteOpenHelper.getWritableDatabase() in onCreate() and then keeping that reference)? Or do you get the DB object from someplace like a helper in each provider method?

通常情况下,如果你只保留本地参考帮助,并得到需要那么这个问题应该消失每种方法的内部可读/写数据库实例。如果不是这样,也许我们可以先看看提供商code?

Typically, if you only keep a local reference to the helper and get the writable/readable database instance inside of each method as needed then this problem should go away. If not, perhaps we can take a look at the provider code?

希望帮助!

这篇关于刷新自定义的ContentProvider /重装数据库引用还原后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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