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)
Adds a change listener to this RealmObject.
|
<E extends RealmObject> |
asObservable()
Returns an Rx Observable that monitors changes to this RealmObject.
|
boolean |
isLoaded()
Determines if the current RealmObject is obtained synchronously or asynchronously (from a worker thread).
|
boolean |
isValid()
Checks if the RealmObject is still valid to use i.e.
|
boolean |
load()
Makes an asynchronous query blocking.
|
void |
removeChangeListener(RealmChangeListener listener)
Removes a previously registered listener.
|
void |
removeChangeListeners()
Removes 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()
public <E extends RealmObject> <any> asObservable()
obj.<MyRealmObjectClass>asObservable()
to pass on
type information, otherwise the type of the following observables will be RealmObject
.E
- RealmObject class that is being observed. Must be this class or its super types.java.lang.UnsupportedOperationException
- if the required RxJava framework is not on the classpath.