Based on previous discussions of best practices here, I employ a factory
method for opening SQLite Databases.
/**
* Factory method ensures only one instance of database in memory.
* @param path on external storage
* @return
*/
static public SQLiteDatabase getInstance(String path)
{
try
{
if(alreadyOpened.containsKey(path))
{
return alreadyOpened.get(path);
}
SQLiteDatabase tdb= SQLiteDatabase.openDatabase(path, null,
SQLiteDatabase.OPEN_READWRITE |SQLiteDatabase.CREATE_IF_NECESSARY);
alreadyOpened.put(path, tdb);
return tdb;
}
catch(Exception ex)
{
Log.e("TileDatabase", "openExisting", ex);
return null;
}
}
This ensures that an SQLiteDatabase is opened once and closed never, which
Diane and others here said is a reasonable pattern.
Nonetheless, I get some reports from some users that their data dissappears
and reappears. In the morning it works, in the afternoon it is not
available, and the next day it is back again.
Ie, there is a query for blobs in this database and is either coming back
with zero results or throwing a SQLiteException that I am handling and
returning not available. If I manage to get logs from the users, I might
know what exception it is.
So in general, my question is this. Is there a reason that SQLiteDatabase
object may become inneffective, due to some changes in the system or
something I am doing, such as leaking a cursor or something? Could a
terminated process, due to Android wanting more memory or a crash, cause me
to be unable to open the database when the process starts again?
Should I be calling SQLiteDatabase.isOpen periodically or anything like
that?
Nathan
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.