当我打电话给dynamicRealm.beginTransaction();
时,仅冻结应用程序就什么也没发生。
下面是代码:
Realm saverealm = Realm.getDefaultInstance();
final DynamicRealm dynamicRealm =
DynamicRealm.getInstance(saverealm.getConfiguration());
final RealmSchema realmSchema = dynamicRealm.getSchema();
dynamicRealm.beginTransaction();
最佳答案
如果交易已经在进行,这将导致应用程序崩溃,正确的方法是:-
try {
realm.beginTransaction();
// body of executeTransaction
realm.commitTransaction();
} catch(Exception e) {
if(realm.isInTransaction()) {
realm.cancelTransaction();
}
throw new RuntimeException(e);
}
或者只是做
realm.executeTransaction()
有关更多信息,请参见此:-https://github.com/realm/realm-java/issues/4217