deleteAllFromRealm(RealmList : This method is only available in managed mode
Android Studio 3.2. , Realm 4.1.0
I need to delete all items in list from Realm.
My snippet:
public static RealmList<Merchant> getMerchantsRealmList() {
Realm realm = Realm.getDefaultInstance();
try {
RealmResults<Merchant> realmResults = realm.where(Merchant.class).findAll();
RealmList<Merchant> realmList = new RealmList<>();
realmList.addAll(realmResults.subList(0, realmResults.size()));
return realmList;
} finally {
realm.close();
}
}
public static void updateMerchantList(final List<Merchant> thatMerchantsList) {
Realm realm = Realm.getDefaultInstance();
try {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmList<Merchant> localMerchantRealmList = getMerchantsRealmList();
if (!EqualsUtil.areEqualContentLists(localMerchantRealmList, thatMerchantsList)) {
List<Merchant> itemNotExistInThatMerchants = new ArrayList<>(localMerchantRealmList);
itemNotExistInThatMerchants.removeAll(thatMerchantsList);
if (itemNotExistInThatMerchants.size() > 0) {
localMerchantRealmList.removeAll(itemNotExistInThatMerchants);
localMerchantRealmList.deleteAllFromRealm(); // error here
}
}
}
});
} finally {
realm.close();
Debug.d(TAG, "updateMerchantList: finish");
}
}
But on runtime I get error in this line :
localMerchantRealmList.deleteAllFromRealm();
Here error:
java.lang.UnsupportedOperationException: This method is only available in managed mode.
at io.realm.RealmList.deleteAllFromRealm(RealmList.java:660)
at com.myproject.customer.service.MerchantService$1.execute(MerchantService.java:107)
at io.realm.Realm.executeTransaction(Realm.java:1393)
at com.myproject.customer.service.MerchantService.updateMerchantList(MerchantService.java:70)
at com.myproject.customer.service.SyncService$1.onSuccess(SyncService.java:49)
at com.myproject.customer.api.DefaultRestClientCallback.onResponse(DefaultRestClientCallback.java:31)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
android realm
add a comment |
Android Studio 3.2. , Realm 4.1.0
I need to delete all items in list from Realm.
My snippet:
public static RealmList<Merchant> getMerchantsRealmList() {
Realm realm = Realm.getDefaultInstance();
try {
RealmResults<Merchant> realmResults = realm.where(Merchant.class).findAll();
RealmList<Merchant> realmList = new RealmList<>();
realmList.addAll(realmResults.subList(0, realmResults.size()));
return realmList;
} finally {
realm.close();
}
}
public static void updateMerchantList(final List<Merchant> thatMerchantsList) {
Realm realm = Realm.getDefaultInstance();
try {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmList<Merchant> localMerchantRealmList = getMerchantsRealmList();
if (!EqualsUtil.areEqualContentLists(localMerchantRealmList, thatMerchantsList)) {
List<Merchant> itemNotExistInThatMerchants = new ArrayList<>(localMerchantRealmList);
itemNotExistInThatMerchants.removeAll(thatMerchantsList);
if (itemNotExistInThatMerchants.size() > 0) {
localMerchantRealmList.removeAll(itemNotExistInThatMerchants);
localMerchantRealmList.deleteAllFromRealm(); // error here
}
}
}
});
} finally {
realm.close();
Debug.d(TAG, "updateMerchantList: finish");
}
}
But on runtime I get error in this line :
localMerchantRealmList.deleteAllFromRealm();
Here error:
java.lang.UnsupportedOperationException: This method is only available in managed mode.
at io.realm.RealmList.deleteAllFromRealm(RealmList.java:660)
at com.myproject.customer.service.MerchantService$1.execute(MerchantService.java:107)
at io.realm.Realm.executeTransaction(Realm.java:1393)
at com.myproject.customer.service.MerchantService.updateMerchantList(MerchantService.java:70)
at com.myproject.customer.service.SyncService$1.onSuccess(SyncService.java:49)
at com.myproject.customer.api.DefaultRestClientCallback.onResponse(DefaultRestClientCallback.java:31)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
android realm
add a comment |
Android Studio 3.2. , Realm 4.1.0
I need to delete all items in list from Realm.
My snippet:
public static RealmList<Merchant> getMerchantsRealmList() {
Realm realm = Realm.getDefaultInstance();
try {
RealmResults<Merchant> realmResults = realm.where(Merchant.class).findAll();
RealmList<Merchant> realmList = new RealmList<>();
realmList.addAll(realmResults.subList(0, realmResults.size()));
return realmList;
} finally {
realm.close();
}
}
public static void updateMerchantList(final List<Merchant> thatMerchantsList) {
Realm realm = Realm.getDefaultInstance();
try {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmList<Merchant> localMerchantRealmList = getMerchantsRealmList();
if (!EqualsUtil.areEqualContentLists(localMerchantRealmList, thatMerchantsList)) {
List<Merchant> itemNotExistInThatMerchants = new ArrayList<>(localMerchantRealmList);
itemNotExistInThatMerchants.removeAll(thatMerchantsList);
if (itemNotExistInThatMerchants.size() > 0) {
localMerchantRealmList.removeAll(itemNotExistInThatMerchants);
localMerchantRealmList.deleteAllFromRealm(); // error here
}
}
}
});
} finally {
realm.close();
Debug.d(TAG, "updateMerchantList: finish");
}
}
But on runtime I get error in this line :
localMerchantRealmList.deleteAllFromRealm();
Here error:
java.lang.UnsupportedOperationException: This method is only available in managed mode.
at io.realm.RealmList.deleteAllFromRealm(RealmList.java:660)
at com.myproject.customer.service.MerchantService$1.execute(MerchantService.java:107)
at io.realm.Realm.executeTransaction(Realm.java:1393)
at com.myproject.customer.service.MerchantService.updateMerchantList(MerchantService.java:70)
at com.myproject.customer.service.SyncService$1.onSuccess(SyncService.java:49)
at com.myproject.customer.api.DefaultRestClientCallback.onResponse(DefaultRestClientCallback.java:31)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
android realm
Android Studio 3.2. , Realm 4.1.0
I need to delete all items in list from Realm.
My snippet:
public static RealmList<Merchant> getMerchantsRealmList() {
Realm realm = Realm.getDefaultInstance();
try {
RealmResults<Merchant> realmResults = realm.where(Merchant.class).findAll();
RealmList<Merchant> realmList = new RealmList<>();
realmList.addAll(realmResults.subList(0, realmResults.size()));
return realmList;
} finally {
realm.close();
}
}
public static void updateMerchantList(final List<Merchant> thatMerchantsList) {
Realm realm = Realm.getDefaultInstance();
try {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmList<Merchant> localMerchantRealmList = getMerchantsRealmList();
if (!EqualsUtil.areEqualContentLists(localMerchantRealmList, thatMerchantsList)) {
List<Merchant> itemNotExistInThatMerchants = new ArrayList<>(localMerchantRealmList);
itemNotExistInThatMerchants.removeAll(thatMerchantsList);
if (itemNotExistInThatMerchants.size() > 0) {
localMerchantRealmList.removeAll(itemNotExistInThatMerchants);
localMerchantRealmList.deleteAllFromRealm(); // error here
}
}
}
});
} finally {
realm.close();
Debug.d(TAG, "updateMerchantList: finish");
}
}
But on runtime I get error in this line :
localMerchantRealmList.deleteAllFromRealm();
Here error:
java.lang.UnsupportedOperationException: This method is only available in managed mode.
at io.realm.RealmList.deleteAllFromRealm(RealmList.java:660)
at com.myproject.customer.service.MerchantService$1.execute(MerchantService.java:107)
at io.realm.Realm.executeTransaction(Realm.java:1393)
at com.myproject.customer.service.MerchantService.updateMerchantList(MerchantService.java:70)
at com.myproject.customer.service.SyncService$1.onSuccess(SyncService.java:49)
at com.myproject.customer.api.DefaultRestClientCallback.onResponse(DefaultRestClientCallback.java:31)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
android realm
android realm
edited Nov 26 '18 at 15:23
Alexei
asked Nov 26 '18 at 13:45
AlexeiAlexei
1,20511125
1,20511125
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When you convert RealmResults
to RealmList
with
RealmList<Merchant> realmList = new RealmList<>();
realmList.addAll(realmResults.subList(0, realmResults.size()));
you created an unmanaged version of your data, meaning the objects in the list are not connected to the database anymore and are basically normal Java objects.
You will have to keep a reference of RealmResults
and delete from it.
RealmResults .removeAll() is depricate. What can I use?
– Alexei
Nov 26 '18 at 16:00
2
RealmResults.deleteAllFromRealm()
– Siyu
Nov 26 '18 at 16:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482471%2fdeleteallfromrealmrealmlist-this-method-is-only-available-in-managed-mode%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you convert RealmResults
to RealmList
with
RealmList<Merchant> realmList = new RealmList<>();
realmList.addAll(realmResults.subList(0, realmResults.size()));
you created an unmanaged version of your data, meaning the objects in the list are not connected to the database anymore and are basically normal Java objects.
You will have to keep a reference of RealmResults
and delete from it.
RealmResults .removeAll() is depricate. What can I use?
– Alexei
Nov 26 '18 at 16:00
2
RealmResults.deleteAllFromRealm()
– Siyu
Nov 26 '18 at 16:04
add a comment |
When you convert RealmResults
to RealmList
with
RealmList<Merchant> realmList = new RealmList<>();
realmList.addAll(realmResults.subList(0, realmResults.size()));
you created an unmanaged version of your data, meaning the objects in the list are not connected to the database anymore and are basically normal Java objects.
You will have to keep a reference of RealmResults
and delete from it.
RealmResults .removeAll() is depricate. What can I use?
– Alexei
Nov 26 '18 at 16:00
2
RealmResults.deleteAllFromRealm()
– Siyu
Nov 26 '18 at 16:04
add a comment |
When you convert RealmResults
to RealmList
with
RealmList<Merchant> realmList = new RealmList<>();
realmList.addAll(realmResults.subList(0, realmResults.size()));
you created an unmanaged version of your data, meaning the objects in the list are not connected to the database anymore and are basically normal Java objects.
You will have to keep a reference of RealmResults
and delete from it.
When you convert RealmResults
to RealmList
with
RealmList<Merchant> realmList = new RealmList<>();
realmList.addAll(realmResults.subList(0, realmResults.size()));
you created an unmanaged version of your data, meaning the objects in the list are not connected to the database anymore and are basically normal Java objects.
You will have to keep a reference of RealmResults
and delete from it.
answered Nov 26 '18 at 15:53
SiyuSiyu
2,8341927
2,8341927
RealmResults .removeAll() is depricate. What can I use?
– Alexei
Nov 26 '18 at 16:00
2
RealmResults.deleteAllFromRealm()
– Siyu
Nov 26 '18 at 16:04
add a comment |
RealmResults .removeAll() is depricate. What can I use?
– Alexei
Nov 26 '18 at 16:00
2
RealmResults.deleteAllFromRealm()
– Siyu
Nov 26 '18 at 16:04
RealmResults .removeAll() is depricate. What can I use?
– Alexei
Nov 26 '18 at 16:00
RealmResults .removeAll() is depricate. What can I use?
– Alexei
Nov 26 '18 at 16:00
2
2
RealmResults.deleteAllFromRealm()
– Siyu
Nov 26 '18 at 16:04
RealmResults.deleteAllFromRealm()
– Siyu
Nov 26 '18 at 16:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482471%2fdeleteallfromrealmrealmlist-this-method-is-only-available-in-managed-mode%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown