I have following problem in my Android app. Assume I have running service which uses SQLite DB. And user decides to unmount the SDcard (connecting to USB or manually) on which is database file located. I got notification intent from my broadcast receiver:
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);
So I'm able to detect card unmounting. In onReceive block of this receiver I explicitly call database.close() on object I use for querying. But my app as sill crashing. Not writing it stopped working, just only switching to homescreen, nothing more.
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
This ends with app crash. But I'm quite sure I have explicitly called close() on the database.
What is the way to close the db so system won't kill my app?
Lot of thanks for all!