public abstract class RealmObject
extends java.lang.Object
An annotation processor will create a proxy class for your RealmObject subclass. The getters and setters should not contain any custom code of logic as they are overridden as part of the annotation process.
A RealmObject is currently limited to the following:
The following field data types are supported:
The types short
, int
, and long
are mapped to long
when storing within a Realm.
Getter and setter names must have the name getXXX
or setXXX
if
the field name is XXX
. Getters for fields of type boolean can be called isXXX
as
well. Fields with a m-prefix must have getters and setters named setmXXX and getmXXX which is
the default behavior when Android Studio automatically generates the getters and setters.
Fields annotated with Ignore
don't have these restrictions and
don't require either a getter or setter.
Realm will create indexes for fields annotated with Index
. This
will speedup queries but will have a negative impact on inserts and updates.
*
A RealmObject cannot be passed between different threads.
Constructor and Description |
---|
RealmObject() |
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(RealmChangeListener listener)
Add a change listener to this RealmObject.
|
boolean |
isLoaded()
Determine if the current RealmObject is obtained synchronously or asynchronously (from
a worker thread).
|
boolean |
isValid()
Check if the RealmObject is still valid to use i.e.
|
boolean |
load()
Make an asynchronous query blocking.
|
void |
removeChangeListener(RealmChangeListener listener)
Remove a previously registered listener.
|
void |
removeChangeListeners()
Remove all registered listeners.
|
void |
removeFromRealm()
Removes the object from the Realm it is currently associated to.
|
public void removeFromRealm()
After this method is called the object will be invalid and any operation (read or write) performed on it will fail with an IllegalStateException
java.lang.IllegalStateException
- if the corresponding Realm is closed or in an incorrect thread.public final boolean isValid()
Realm
been closed. It will always return false for stand alone
objects.true
if the object is still accessible, false
otherwise or if it is a
standalone object.public final boolean isLoaded()
true
for them.
This will return true
if called for a standalone object (created outside of Realm).true
if the query has completed and the data is available false
if the
query is in progress.public final boolean load()
true
if called for a standalone object (created outside of Realm).true
if it successfully completed the query, false
otherwise.public final void addChangeListener(RealmChangeListener listener)
listener
- the change listener to be notified.public final void removeChangeListener(RealmChangeListener listener)
listener
- the instance to be removed.public final void removeChangeListeners()