public class Subscription extends RealmObject
They are created automatically when using RealmQuery.findAllAsync()
or RealmQuery.findAllAsync(String)
on those Realms, but can also be created manually using RealmQuery.subscribe()
and RealmQuery.subscribe(String)
.
As long as any subscription exist that include an object, that object will be present on the device. If an object is not covered by an active subscription it will be removed from the device, but not the server.
Subscriptions are Realm objects, so deleting them e.g. by calling RealmObject.deleteFromRealm()
,
is the same as calling unsubscribe()
.
Warning: Instances of this class should never be created directly through
Realm.createObject(Class)
but only by using RealmQuery.subscribe()
or
RealmQuery.subscribe(String)
.
Modifier and Type | Class and Description |
---|---|
static class |
Subscription.State
The different states a Subscription can be in.
|
Constructor and Description |
---|
Subscription() |
Subscription(String name,
RealmQuery<?> query)
Creates a unmanaged named subscription from a
RealmQuery . |
Modifier and Type | Method and Description |
---|---|
String |
getErrorMessage()
Returns the error message if
getState() returned Subscription.State.ERROR , otherwise
the empty string is returned. |
String |
getName()
Returns the name of the subscription.
|
String |
getQueryClassName()
Returns the internal name of the Class being queried.
|
String |
getQueryDescription()
Returns a textual description of the query that created this subscription.
|
Subscription.State |
getState()
Returns the state of the subscription
|
String |
toString() |
void |
unsubscribe()
Cancels the subscription.
|
addChangeListener, addChangeListener, addChangeListener, addChangeListener, asChangesetObservable, asChangesetObservable, asFlowable, asFlowable, deleteFromRealm, deleteFromRealm, getRealm, getRealm, isLoaded, isLoaded, isManaged, isManaged, isValid, isValid, load, load, removeAllChangeListeners, removeAllChangeListeners, removeChangeListener, removeChangeListener, removeChangeListener, removeChangeListener
public Subscription()
public Subscription(String name, RealmQuery<?> query)
RealmQuery
.
This will not take effect until it has been added to the Realm.name
- name of the query.query
- the query to turn into a subscription.public String getName()
public String getQueryDescription()
public String getQueryClassName()
public Subscription.State getState()
Subscription.State
public String getErrorMessage()
getState()
returned Subscription.State.ERROR
, otherwise
the empty string is returned.public void unsubscribe()
The effect of unsubscribing is not immediate. The local Realm must coordinate with the Realm Object Server before it can happen. When it happens, any objects removed will trigger a standard change notification, and from the perspective of the device it will look like they where deleted.
Calling this method is the equivalent of calling RealmObject.deleteFromRealm()
.
IllegalStateException
- if the Realm is not in a write transaction.