Clean up old Realm objects?

Brandon Zamudio :

Is there a simple way to delete old data from a Realm database? Like if some object has one day stored automatically delete it?

The alternative could be to add a field with the date and extract and compare it to decide if delete, but the question is if Realm has a method itself to achieve this.

I already saw some similar questions (like this one) about this, but none for Android (or Java), in the Realm docs the only similar approach I found is about migrations.

The question is whether there is any other way to automatically remove old objects from Realm, such as a condition when we store data, a parameter, a configuration or a Realm method, and not just compare each time. It is obvious that with a query we can eliminate any object that we want.

The specification of the linked question (not the answer), is just to clarify that this is not a Swift-based question and not mark it as duplicate at first glance.

A.jiji :

Nope, there is not such functionality in Realm itself.

Your alternative is good but I do not recommend to use background service for deleting data, so check/delete data when you query.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=429711&siteId=1