开发者

Android: Access to AssetManager inside a singleton class?

开发者 https://www.devze.com 2023-04-04 06:10 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消