且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

安卓:我可以用一个SQLiteOpenHelper类多个数据库文件?

更新时间:2023-02-09 11:18:43

当然,你可以。这只是你的助手一流的设计问题。您可以DB的名称只是传递给你的助手类的构造函数(连同所需的上下文实例),而不是硬编码:

Of course, you can. It is just a matter of your Helper class design. You can just pass the name of DB to your Helper class constructor (along with required Context instance) instead of hardcoding:

public class DBOpenHelper extends SQLiteOpenHelper {

    public Helper(Context context, String dbName, int dbVersion) {
        super(context, dbName, null, dbVersion);
    }
...
}