Android: Access to AssetManager inside a singleton class?
I have a singleton class which manages data and database handling of my application. I create a sqlite3 database with default values and kept it in the asset directory. In one of my APIs of this class I have made a check that if DB doesn't exist in /data/data//my.db then copy it from asset directory to this location.
Given my class is singleton and doesn't inherit from UI classes, Is this possible that 开发者_如何学PythonI can write this API in my current setup or I have to rethink some alternate design?
Class DBHandler {
// singleton class
public void initDatabase() {
File dbFile = new File("/data/data/<mypackage/a.db>");
if (dbFile.exists()) {
return;
}
//copy database from asset directory
//How to do this here?????
}
};
I want to know is this possible??
Pass a Context
reference to initDatabase()
, then you can use its methods to acceess files and databases in your app's private directory.
精彩评论