0

我的 Android 应用程序中有以下问题。假设我正在运行使用 SQLite DB 的服务。并且用户决定卸载数据库文件所在的 SD 卡(连接到 USB 或手动)。我从广播接收器收到通知意图:

    IntentFilter MIF = new IntentFilter(Intent.ACTION_MEDIA_REMOVED);
    MIF.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    MIF.addAction(Intent.ACTION_MEDIA_EJECT);
    MIF.addDataScheme("file");
    registerReceiver(MediaReceiver,MIF);

所以我能够检测到卡卸载。在此接收器的 onReceive 块中,我在用于查询的对象上显式调用 database.close()。但是我的应用程序崩溃了。不写它就停止工作,只是切换到主屏幕,仅此而已。

    02-14 23:23:30.586: E/ProcessKiller(127): Process cz.cuni.mff.drozi.Metro (27598) has open file /mnt/secure/staging/Android/data/cz.cuni.mff.drozi.Metro/files/database.db
    02-14 23:23:31.826: E/ProcessKiller(127): Process cz.cuni.mff.drozi.Metro (27598) has open file /mnt/secure/staging/Android/data/cz.cuni.mff.drozi.Metro/files/database.db
    02-14 23:23:33.056: E/ProcessKiller(127): Process cz.cuni.mff.drozi.Metro (27598) has open file /mnt/secure/staging/Android/data/cz.cuni.mff.drozi.Metro/files/database.db
    02-14 23:23:34.276: E/ProcessKiller(127): Process cz.cuni.mff.drozi.Metro (27598) has open file /mnt/secure/staging/Android/data/cz.cuni.mff.drozi.Metro/files/database.db
    02-14 23:23:35.496: E/ProcessKiller(127): Process cz.cuni.mff.drozi.Metro (27598) has open file /mnt/secure/staging/Android/data/cz.cuni.mff.drozi.Metro/files/database.db
     02-14 23:23:36.706: E/ProcessKiller(127): Process cz.cuni.mff.drozi.Metro (27598) has open file /mnt/secure/staging/Android/data/cz.cuni.mff.drozi.Metro/files/database.db

这以应用程序崩溃结束。但我很确定我已经在数据库上明确调用了 close() 。

关闭数据库以使系统不会杀死我的应用程序的方法是什么?

非常感谢大家!

4

0 回答 0