Android 在SqliteOpenHelper中更改数据库

Android 在SqliteOpenHelper中更改数据库,android,sqlite,sqliteopenhelper,Android,Sqlite,Sqliteopenhelper,有没有一种方法可以更改SQLiteOpenHelper对象使用的数据库,而不必强制使用该助手的每个类替换它们的类实例 我之所以要更改数据库,是因为我在两个具有相同表结构的独立数据库中有一些实时数据和一些脱机数据。我更新脱机数据,然后交换它们,这样我就可以在大的插入上锁定脱机数据库。您必须使用来访问只有一个实例的数据库 看起来像 public class SingletonDemo { private static SingletonDemo instance = null

有没有一种方法可以更改SQLiteOpenHelper对象使用的数据库,而不必强制使用该助手的每个类替换它们的类实例

我之所以要更改数据库,是因为我在两个具有相同表结构的独立数据库中有一些实时数据和一些脱机数据。我更新脱机数据,然后交换它们,这样我就可以在大的插入上锁定脱机数据库。

您必须使用来访问只有一个实例的数据库 看起来像

    public class SingletonDemo {
        private static SingletonDemo instance = null;
        private SingletonDemo() { // do what you want here}
        public static SingletonDemo getInstance() {
            if (instance == null) {
                synchronized (SingletonDemo.class) {
                    if (instance == null) {
                        instance = new SingletonDemo();
                    }
                }
            }
            return instance;
        }

...
// Add all the class function you need here

    }
这是线程安全的,可以在任何需要的地方使用