【问题标题】:Avoid database corrupted if android kills while creating如果android在创建时杀死,避免数据库损坏
【发布时间】:2012-04-14 15:50:42
【问题描述】:

提前致谢!

我想知道如果 android 杀死您的应用程序会发生什么,如果此时您正在创建数据库结构。 就我而言,创建数据库需要一段时间,因为要插入很多元素(大约 20/25 秒)。如果用户认为“我要在邮件结束时检查我的邮件”并将我的应用程序置于后台,android 将能够杀死该应用程序(如文档所述) ¿ 怎样才能避免呢?此时,datacase 从 AsyncTask 创建以不阻塞用户界面... ¿您如何看待这个(可能的)问题?

再次感谢,问候!!

【问题讨论】:

    标签: android sqlite lifecycle


    【解决方案1】:

    使用 SQLite 事务!它不仅可以加快数据库操作,还可以避免数据库损坏的危险。

    【讨论】:

    • 嗨,很抱歉我的回复迟了。 In 似乎是一个不错的解决方案,但提交 3000 次或更多插入不会有问题?
    • 事实上,它总是建议对大量插入使用事务。它加快了处理速度。 SQLite 官网是这样说的:By default, each INSERT statement is its own transaction. But if you surround multiple INSERT statements with BEGIN...COMMIT then all the inserts are grouped into a single transaction. The time needed to commit the transaction is amortized over all the enclosed insert statements and so the time per insert statement is greatly reduced
    • 好的!谢谢你的快速回复,我错了!每天都学点东西真好,呵呵
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    相关资源
    最近更新 更多