@Override public void onCreate() { super.onCreate(); Realm.init(this); Realm.setDefaultConfiguration(new RealmConfiguration.Builder().schemaVersion(7) // .migration(new RealmMigration() { @Override public void migrate(@NonNull DynamicRealm realm, long oldVersion, long newVersion) { RealmAutoMigration.migrate(realm); } }) // .initialData(realm -> { Cat cat = new Cat(); for(CatNames catName : CatNames.values()) { cat.setName(catName.getName()); realm.insert(cat); } }) // .build()); SingletonComponent singletonComponent = DaggerSingletonComponent.create(); Injector.setComponent(singletonComponent); }
@Override public void onCreate() { super.onCreate(); sInstance = this; RealmConfiguration configuration = new RealmConfiguration.Builder(this).deleteRealmIfMigrationNeeded() .migration(new RealmMigration() { @Override public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { } }) .name("chao.realm") .build(); Realm.setDefaultConfiguration(configuration); Stetho.initialize(Stetho.newInitializerBuilder(this) .enableDumpapp(Stetho.defaultDumperPluginsProvider(this)) .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build()) .build()); FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); }
@Override public void onCreate() { super.onCreate(); mAppContext = this; // 配置Realm数据库 RealmConfiguration configuration = new RealmConfiguration .Builder(this) .deleteRealmIfMigrationNeeded() .schemaVersion(6) .migration(new RealmMigration() { @Override public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { } }).build(); Realm.setDefaultConfiguration(configuration); //配置腾讯bugly CrashReport.initCrashReport(getApplicationContext(), ConstantUtil.BUGLY_ID, false); }
@Override public void onCreate() { super.onCreate(); RealmConfiguration config = new RealmConfiguration.Builder(getApplicationContext()) .name(getResources().getString(R.string.database_conf_name)) .schemaVersion(getResources().getInteger(R.integer.database_conf_version)) .modules(new DbModule()) .deleteRealmIfMigrationNeeded() .migration(new RealmMigration() { @Override public void migrate(DynamicRealm dynamicRealm, long l, long l1) { Log.d(TAG, "migrate l [" + l + "] l1 [" + l1 + "]"); } }) .build(); Realm.setDefaultConfiguration(config); }
public static void initDefaultRealm(@NonNull String dbSuffix, int version, RealmMigration realmMigration) { Realm.removeDefaultConfiguration(); RealmConfiguration.Builder builder = new RealmConfiguration.Builder() .name("db_realm_" + dbSuffix) .schemaVersion(version) .rxFactory(new RealmObservableFactory()); // .deleteRealmIfMigrationNeeded(); if (realmMigration != null) builder.migration(realmMigration); RealmConfiguration realmConfiguration = builder.build(); Realm.setDefaultConfiguration(realmConfiguration); }
/** * 初始化 */ public static void init(Context context) { if (sInstance == null) { if (context != null && context instanceof Application) { sInstance = (Application) context; /** * 初始化Realm数据库 */ Realm.init(context); Realm.setDefaultConfiguration(new RealmConfiguration.Builder() // .directory(context.getFilesDir()) // .name(Realm.DEFAULT_REALM_NAME) // .encryptionKey(null) .schemaVersion(4) .migration(new RealmMigration() { @Override public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { Log.e("Realm: migrate", "数据库迁移@oldVersion: " + oldVersion + "@newVersion: " + newVersion); } }) .deleteRealmIfMigrationNeeded() .build()); Stetho.initialize(Stetho.newInitializerBuilder(context) .enableDumpapp(Stetho.defaultDumperPluginsProvider(context)) .enableWebKitInspector(RealmInspectorModulesProvider.builder(context) // .withFolder(context.getCacheDir()) // .withEncryptionKey("encrypted.realm", "MagicCube".getBytes()) // .withMetaTables() // .withDescendingOrder() // .withLimit(1000) // .databaseNamePattern(Pattern.compile(".+\\.realm")) .build()) .build()); } else { throw new IllegalArgumentException("context is null or doesn't Application Instance!"); } } else { Log.e("DBHelper: init", "sInstance != null ==> 重复初始化!"); } }
@Singleton @Provides RealmConfiguration provideRealmConfiguration(Context context) { return new RealmConfiguration.Builder(context) .name("deglancer.realm") .schemaVersion(3) .deleteRealmIfMigrationNeeded() .migration(new RealmMigration() { @Override public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { } }) .build(); }
public static RealmMigration getMigration() { return migration; }