E - Indicates the callback type, which is inherited from IRemoteBroker.public class RemoteObjectCallbackList<E extends IRemoteBroker> extends Object
In details, this class:
IRemoteBroker callbacks in a Map container.
Each callback is uniquely identified by an IRemoteObject
(obtained by calling IRemoteBroker#asObject().IRemoteObject.DeathRecipient object to each registered callback
so that a callback is automatically removed from the list when the process hosting the callback dies.When constructing a RemoteObjectCallbackList instance,
you need to pass E to specify the callback type.
E is inherited from IRemoteBroker.
| 构造器 | 说明 |
|---|---|
RemoteObjectCallbackList() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
Object |
getBroadcastCookie(int index) |
Obtains the cookie associated with the callback matching the given index in the broadcast.
|
E |
getBroadcastInterface(int index) |
Obtains the callback matching the given index in the broadcast.
|
Object |
getRemoteObjectCallbackCookie(IRemoteObject key) |
Obtains the cookie associated with the callback identified by the specified
IRemoteObject. |
int |
getRemoteObjectCallbackCount() |
Obtains the number of callbacks stored in this container.
|
E |
getRemoteObjectCallbackInterface(IRemoteObject key) |
Obtains the callback identified by the specified
IRemoteObject. |
void |
onRemoteCallbackDied(E callback) |
Called when the process hosting the specified callback dies.
|
void |
onRemoteCallbackDied(E callback,
Object cookie) |
Called when the process hosting the specified callback dies, with a
cookie containing additional data. |
boolean |
register(E callback) |
Adds the specified callback to this
RemoteObjectCallbackList. |
boolean |
register(E callback,
Object cookie) |
Adds the specified callback with the specified cookie to this
RemoteObjectCallbackList. |
int |
startBroadcast() |
Starts a broadcast.
|
void |
stopBroadcast() |
Stops a broadcast.
|
boolean |
unregister(E callback) |
Removes a previously added callback from this
RemoteObjectCallbackList. |
void |
unregisterAll() |
Removes all previously added callbacks from this
RemoteObjectCallbackList. |
public void onRemoteCallbackDied(E callback)
cookie.
You can override this method to define subsequent operations.
callback - Indicates the callback hosted by the process.
Since the process has died, you can no longer invoke this callback.public void onRemoteCallbackDied(E callback, Object cookie)
cookie containing additional data.
You can override this method to define subsequent operations.
callback - Indicates the callback hosted by the process.
Since the process has died, you can no longer invoke this callback.cookie - Indicates the cookie associated with the callback. It can be any object.public int getRemoteObjectCallbackCount()
public E getRemoteObjectCallbackInterface(IRemoteObject key)
IRemoteObject.key - Indicates the specified IRemoteObject.IRemoteObject.
The callback was added to the RemoteObjectCallbackList using register(E).public Object getRemoteObjectCallbackCookie(IRemoteObject key)
IRemoteObject.key - Indicates the specified IRemoteObject.IRemoteObject.
The callback was added to the RemoteObjectCallbackList using register(E).public boolean register(E callback)
RemoteObjectCallbackList.
This callback will remain in the RemoteObjectCallbackList until unregister(E) is called
to remove it from the list or the process hosting the callback dies.
callback - Indicates the callback to add.true if the callback is added to this RemoteObjectCallbackList;
returns false if the callback fails to be added to this RemoteObjectCallbackList
or unregisterAll() has been called.public boolean register(E callback, Object cookie)
RemoteObjectCallbackList.
The cookie associated with the callback is also added to this RemoteObjectCallbackList.
This callback will remain in the RemoteObjectCallbackList until unregister(E) is called
to remove it from the list or the process hosting the callback dies.
callback - Indicates the callback to add.cookie - Indicates the cookie associated with the callback. It can be any object.true if the callback is added to this RemoteObjectCallbackList;
returns false if the callback fails to be added to this RemoteObjectCallbackList
or unregisterAll() has been called.public boolean unregister(E callback)
RemoteObjectCallbackList.callback - Indicates the callback to remove.true if the specified callback is found
and removed from this RemoteObjectCallbackList;
returns false if the specified callback is not found.public void unregisterAll()
RemoteObjectCallbackList.
After removing all callbacks from this RemoteObjectCallbackList
and marking the list as unavailable, calling register(E) to add callbacks to this list will fail.
This method is used to prevent clients from registering callbacks after the service has stopped.
public int startBroadcast()
This method creates a copy of the callback list and starts invoking registered callbacks.
You can retrieve callbacks from the list using getBroadcastInterface(int) and getBroadcastCookie(int).
Only one broadcast is allowed at a time. Ensure that you always call this method from the same thread
and that you call stopBroadcast() after calling this method.
getBroadcastInterface(int) and getBroadcastCookie(int);
otherwise returns -1 if another broadcast is running.public void stopBroadcast()
You must call this method after a broadcast is done.
public E getBroadcastInterface(int index)
This method can be called only after a broadcast is started,
and its data is no longer valid after stopBroadcast() is called.
If the returned callback has disappeared when you call it, the RemoteException will be thrown.
You need to catch this exception, but you can handle it by simply ignoring it
because the callback list automatically removes invalid callbacks.
index - Indicates the callback index. It cannot exceed the return value of startBroadcast().public Object getBroadcastCookie(int index)
index - Indicates the callback index. It cannot exceed the return value of startBroadcast().