代码之家  ›  专栏  ›  技术社区  ›  EboMike

Database randomly deletes itself every so often

  •  2
  • EboMike  · 技术社区  · 14 年前

    I have a normal SQLite database in my app, managed through my own ContentProvider and implemented via SQLiteOpenHelper.

    On the Droid only, every few weeks or so, the database just disappears. I have several users who wrote me about that, and I've seen it myself too now. I added some debug info (hard to repro when you only see it every few weeks), and in one instance, it just happened inbetween widget updates - first, the widget is displayed and shows the data just fine, the next time, the SQLiteOpenHelper's onCreate is called.

    再一次,这只在机器人身上。我从未在G1上看到过。我从来没有关闭数据库,但它是一个内容提供商,听起来好像我不应该首先做这件事(我记得Hakbod说,这个想法是,OS将关闭应用程序的过程中,必要时,这将自动关闭数据库)。

    有什么想法吗?

    1 回复  |  直到 14 年前
        1
  •  1
  •   EboMike    14 年前

    According to the documentation, SQLiteDatabase has locking enabled by default ( SQLiteDatabase.setLockingEnabled )In my app, I explicitly turn it on after opening, and added some other more paranoid synchronization to make sure multiple threads can't access the database at the same time, and that seems to have fixed it.

    我仍然好奇为什么这个问题只发生在摩托罗拉Droid上,我有这样的预感,默认情况下这个手机已经关闭了,但听起来有点奇怪——毕竟,机器人是一个几乎没有制造商定制的手机。

    In any case, explicitly enabling locking and proper synchronization did the trick for me.