public final class ServiceConnector
extends java.lang.Object
To use a ServiceConnector,
@ServiceInfo(serviceIntent="com.myintent.MY_SERVICE")
private IMYService myService;
@ServiceConnectionCallback
public void onServiceConnectionChanged(String serviceIntent, boolean connected) {
}
Call bind(Object, Context)
ServiceConnector| Modifier and Type | Method and Description |
|---|---|
static void |
bind(java.lang.Object target,
Context context)
Call this to process the given target object to look for any
IInterface fields annotated with ServiceInfo,
and if so connects to those services. |
static boolean |
isAllConnected()
Returns true if all the annotated services are connected.
|
static boolean |
isConnected(java.lang.String serviceIntent)
Returns true if connected with a service of the given intent.
|
static void |
setEnableDebug(boolean enableDebug)
Call to enable or disable debug logs
|
static void |
unbind(java.lang.Object target)
Disconnects from all the services bounded to this target.
|
static void |
waitForAllConnected(long timeout)
Blocks for up to the given timeout for the connection with all the services
|
static void |
waitForConnected(long timeout,
java.lang.String serviceIntent)
Blocks for up to the given timeout for the connection to the given service.
|
public static void bind(java.lang.Object target,
Context context)
IInterface fields annotated with ServiceInfo,
and if so connects to those services.
Those fields will get initialized with the remote
IInterface service objects when the service is
successfully connected.target - The object to analyzecontext - Context used to connect to servicepublic static void unbind(java.lang.Object target)
target - The target used to bind.public static boolean isAllConnected()
public static boolean isConnected(java.lang.String serviceIntent)
serviceIntent - The intent of service to check forpublic static void waitForConnected(long timeout,
java.lang.String serviceIntent)
throws java.lang.InterruptedException
timeout - Maximum timeout in ms to wait for. 0 Waits until service is connectedserviceIntent - The service intentjava.lang.InterruptedExceptionpublic static void waitForAllConnected(long timeout)
throws java.lang.InterruptedException
timeout - Maximum timeout in ms to wait for. 0 Waits until service is connectedjava.lang.InterruptedExceptionpublic static void setEnableDebug(boolean enableDebug)
enableDebug - Enable or disable