use of fr.neamar.kiss.dataprovider.Provider in project KISS by Neamar.
the class DataHandler method connectToProvider.
/**
* Require the data handler to be connected to the data provider with the given name
*
* @param name Data provider name (i.e.: `ContactsProvider` → `"contacts"`)
*/
protected void connectToProvider(final String name) {
// Do not continue if this provider has already been connected to
if (this.providers.containsKey(name)) {
return;
}
// Find provider class for the given service name
Intent intent = this.providerName2Intent(name);
if (intent == null) {
return;
}
// Send "start service" command first so that the service can run independently
// of the activity
this.context.startService(intent);
final ProviderEntry entry = new ProviderEntry();
// Connect and bind to provider service
this.context.bindService(intent, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
Provider.LocalBinder binder = (Provider.LocalBinder) service;
IProvider provider = binder.getService();
// Update provider info so that it contains something useful
entry.provider = provider;
entry.connection = this;
if (provider.isLoaded()) {
handleProviderLoaded();
}
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
}
}, Context.BIND_AUTO_CREATE);
// Add empty provider object to list of providers
this.providers.put(name, entry);
}
Aggregations