Search in sources :

Example 41 with RealmConfiguration

use of io.realm.RealmConfiguration in project ARD by MobileApplicationsClub.

the class ARD method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    Realm.init(this);
    final RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name(AHC.REALM_ARD_DATABASE).schemaVersion(AHC.REALM_ARD_DATABASE_SCHEMA).build();
    Realm.setDefaultConfiguration(realmConfiguration);
}
Also used : RealmConfiguration(io.realm.RealmConfiguration)

Example 42 with RealmConfiguration

use of io.realm.RealmConfiguration in project Now by XunMengWinter.

the class BaseListFragment method initRealm.

protected void initRealm() {
    RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();
    mRealm = Realm.getInstance(realmConfiguration);
    mRealmDbHelper = new RealmDbHelper(mList, mRealm, getNowRealmClass());
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) RealmDbHelper(top.wefor.now.data.database.RealmDbHelper)

Example 43 with RealmConfiguration

use of io.realm.RealmConfiguration in project CustomViews by AndroidStudy233.

the class RealmManager method init.

/**
 * 初始化realm,比如说如果你的app在不同的账号登录同一台设备就要需要建立不同的数据库(根据名称来区分)
 *
 * @param realmName 数据库名称
 * @param version   版本号
 */
private static void init(String realmName, int version) {
    RealmConfiguration configuration = new RealmConfiguration.Builder().name(// 配置名字
    realmName).encryptionKey(// 加密用字段,不是64位会报错
    new byte[64]).schemaVersion(// 版本号
    version).migration(new RealmMigration() {

        @Override
        public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
            MyLogUtil.debug("oldVersion: " + oldVersion);
            MyLogUtil.debug("newVersion: " + newVersion);
            RealmObjectSchema schema = realm.getSchema().get("Doctor");
            Set<String> names = schema.getFieldNames();
            if (names.contains("id"))
                schema.removeField("id");
            if (names.contains("name") && !schema.getPrimaryKey().equals("name")) {
                schema.removePrimaryKey();
                schema.addPrimaryKey("name");
            }
        }
    }).build();
    Realm.setDefaultConfiguration(configuration);
// Context.getFilesDir() 目录下的realmName.realm数据库
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) DynamicRealm(io.realm.DynamicRealm) RealmObjectSchema(io.realm.RealmObjectSchema) RealmMigration(io.realm.RealmMigration)

Example 44 with RealmConfiguration

use of io.realm.RealmConfiguration in project underlx by underlx.

the class Application method initRealm.

public static void initRealm(Context context) {
    // Initialize Realm. Should only be done once when the application starts.
    Realm.init(context);
    RealmConfiguration config = new RealmConfiguration.Builder().schemaVersion(// Must be bumped when the schema changes
    8).migration(new MyMigration()).build();
    Realm.setDefaultConfiguration(config);
}
Also used : RealmConfiguration(io.realm.RealmConfiguration)

Example 45 with RealmConfiguration

use of io.realm.RealmConfiguration in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class AndroidIMSICatcherDetector method onCreate.

@Override
public void onCreate() {
    instance = new WeakReference<>(this);
    addModule(new AndroidLoggerModule());
    addModule(OkHttpModule.withCache(this));
    super.onCreate();
    RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this).deleteRealmIfMigrationNeeded().build();
    Realm.setDefaultConfiguration(realmConfiguration);
    final Realm realm = Realm.getDefaultInstance();
    realm.executeTransactionAsync(new DefaultDataTransaction(), new Realm.Transaction.OnSuccess() {

        @Override
        public void onSuccess() {
            log.debug("Loading default data successful");
            realm.close();
        }
    }, new Realm.Transaction.OnError() {

        @Override
        public void onError(Throwable error) {
            log.error("Error loading default data", error);
            realm.close();
        }
    });
    TinyDB.getInstance().init(getApplicationContext());
    TinyDB.getInstance().putBoolean(TinyDbKeys.FINISHED_LOAD_IN_MAP, true);
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) DefaultDataTransaction(com.secupwn.aimsicd.data.DefaultDataTransaction) DefaultDataTransaction(com.secupwn.aimsicd.data.DefaultDataTransaction) Realm(io.realm.Realm) AndroidLoggerModule(io.freefair.android.injection.modules.AndroidLoggerModule)

Aggregations

RealmConfiguration (io.realm.RealmConfiguration)64 Realm (io.realm.Realm)20 DynamicRealm (io.realm.DynamicRealm)17 Scheduler (io.reactivex.Scheduler)14 RealmChangeListener (io.realm.RealmChangeListener)8 BeforeExperiment (dk.ilios.spanner.BeforeExperiment)6 Before (org.junit.Before)5 DynamicRealmObject (io.realm.DynamicRealmObject)4 RealmList (io.realm.RealmList)4 RealmResults (io.realm.RealmResults)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Context (android.content.Context)3 OrderedCollectionChangeSet (io.realm.OrderedCollectionChangeSet)3 OrderedRealmCollectionChangeListener (io.realm.OrderedRealmCollectionChangeListener)3 RealmObjectSchema (io.realm.RealmObjectSchema)3 AllTypes (io.realm.entities.AllTypes)3 IntentFilter (android.content.IntentFilter)2 LinearLayout (android.widget.LinearLayout)2 RealmSchema (io.realm.RealmSchema)2