S
- The service interface that is being encapsulated.public abstract class ServiceConnector<S extends IInterface> extends Object implements ServiceConnection
Connection with the service happens implicitly. However, the user of a ServiceConnector
must call disconnect()
when he or she is done with the instance. For example,
when using a ServiceConnector
in an Activity
, call disconnect()
from
onPause()
or onDestroy()
.
Modifier and Type | Class and Description |
---|---|
static interface |
ServiceConnector.Callback<T>
Responds to the results of a call to a
ServiceConnector method. |
static interface |
ServiceConnector.OnServiceConnectedListener |
protected static interface |
ServiceConnector.ServiceCallable<S,T> |
protected static interface |
ServiceConnector.ServiceRunnable<S> |
Modifier and Type | Field and Description |
---|---|
protected Account |
mAccount |
protected ServiceConnector.OnServiceConnectedListener |
mClient |
protected boolean |
mConnected |
protected Context |
mContext |
protected Handler |
mHandler |
protected S |
mService |
Constructor and Description |
---|
ServiceConnector(Context context,
Account account,
ServiceConnector.OnServiceConnectedListener client)
Constructs a new ServiceConnector object.
|
Modifier and Type | Method and Description |
---|---|
boolean |
connect() |
void |
disconnect() |
protected <T> T |
execute(ServiceConnector.ServiceCallable<S,T> callable) |
protected <T> void |
execute(ServiceConnector.ServiceCallable<S,T> callable,
ServiceConnector.Callback<T> callback) |
protected void |
execute(ServiceConnector.ServiceRunnable<S> runnable) |
protected void |
execute(ServiceConnector.ServiceRunnable<S> runnable,
ServiceConnector.Callback<Void> callback) |
S |
getService()
Returns the order service interface
|
protected abstract String |
getServiceIntentAction() |
protected String |
getServiceIntentPackage()
The package which hosts the service to connect to.
|
protected int |
getServiceIntentVersion()
Deprecated.
Include a version in the service connector action instead
|
protected abstract S |
getServiceInterface(IBinder iBinder) |
protected Intent |
getStartIntent() |
boolean |
isConnected()
Returns whether we are connected to the order service
|
boolean |
isInstalled() |
protected void |
notifyServiceConnected(ServiceConnector.OnServiceConnectedListener client) |
protected void |
notifyServiceDisconnected(ServiceConnector.OnServiceConnectedListener client) |
void |
onServiceConnected(ComponentName componentName,
IBinder iBinder)
Part of the ServiceConnection interface.
|
void |
onServiceDisconnected(ComponentName componentName)
Part of the ServiceConnection interface.
|
protected <T> void |
postResults(T result,
ResultStatus status,
ServiceConnector.Callback<T> callback) |
protected void |
throwOnFailure(ResultStatus status) |
protected S |
waitForConnection() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onBindingDied, onNullBinding
protected final Context mContext
protected final Account mAccount
protected final ServiceConnector.OnServiceConnectedListener mClient
protected final Handler mHandler
protected S extends IInterface mService
protected boolean mConnected
public ServiceConnector(Context context, Account account, ServiceConnector.OnServiceConnectedListener client)
context
- the Context object, required for establishing a connection to
the service.account
- the Account to use with the service.client
- an optional object implementing the OnServiceConnectedListener
interface, for receiving connection notifications from the service.protected abstract String getServiceIntentAction()
protected String getServiceIntentPackage()
@Deprecated protected int getServiceIntentVersion()
getServiceIntentAction()
instead of using this mechanism.public boolean connect()
public boolean isInstalled()
protected Intent getStartIntent()
public void disconnect()
protected S waitForConnection() throws BindingException
BindingException
public boolean isConnected()
public S getService()
protected void execute(ServiceConnector.ServiceRunnable<S> runnable) throws RemoteException, ClientException, ServiceException, BindingException
protected <T> T execute(ServiceConnector.ServiceCallable<S,T> callable) throws RemoteException, ClientException, ServiceException, BindingException
protected <T> void execute(ServiceConnector.ServiceCallable<S,T> callable, ServiceConnector.Callback<T> callback)
protected void execute(ServiceConnector.ServiceRunnable<S> runnable, ServiceConnector.Callback<Void> callback)
protected void throwOnFailure(ResultStatus status) throws ClientException, ServiceException
ClientException
ServiceException
protected <T> void postResults(T result, ResultStatus status, ServiceConnector.Callback<T> callback)
protected void notifyServiceConnected(ServiceConnector.OnServiceConnectedListener client)
protected void notifyServiceDisconnected(ServiceConnector.OnServiceConnectedListener client)
public final void onServiceConnected(ComponentName componentName, IBinder iBinder)
onServiceConnected
in interface ServiceConnection
public final void onServiceDisconnected(ComponentName componentName)
onServiceDisconnected
in interface ServiceConnection