Manmohan Soni
Manmohan Soni

Reputation: 6621

Do we need to commit transaction ''realm.commitTransaction'' while using realm.executeTransactionAsync method?

What i found during testing of my application. I have copy some data to realm database and then from other process i.e. SyncAdapter the data is updated by copy or update method using realm.executeTransactionAsync call. As run the sync multiple time and remove the app from recents. The data is rollback to old data. Do any one have solution for this. Following is my code snippet:

final Realm realm = getRealm();
        realm.executeTransactionAsync(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                for (GetProductPriceResModel priceResModel : resBeanList)
                    priceResModel.generateSearchData();
                realm.copyToRealmOrUpdate(resBeanList);
                realm.commitTransaction();
            }
        }, new Realm.Transaction.OnSuccess() {
            @Override
            public void onSuccess() {
                if (callBack != null) callBack.onSuccess();
                closeRealm(realm);
            }
        }, new Realm.Transaction.OnError() {
            @Override
            public void onError(Throwable error) {
                if (callBack != null) callBack.onFailure(error);
            }
        });

Upvotes: 1

Views: 1286

Answers (1)

Aks4125
Aks4125

Reputation: 5720

When you use executeTransaction or executeTransactionAsync then you don't need to call beginTransaction & commitTransaction, which is automatically called by realm itself.

Source

Upvotes: 1

Related Questions