Skip to content

Instantly share code, notes, and snippets.

@soygul
Last active October 30, 2018 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soygul/dc9798853191ed5ed766 to your computer and use it in GitHub Desktop.
Save soygul/dc9798853191ed5ed766 to your computer and use it in GitHub Desktop.
Android local service binding - code snippet
/*************************
* Local service binding *
*************************/
private final IBinder binder = new WorkerServiceBinder();
/**
* Returns an instance of this service so binding components can directly call public methods of this service.
*/
public class WorkerServiceBinder extends Binder {
WorkerService getService() {
return WorkerService.this;
}
}
@Override
public IBinder onBind(Intent intent) {
String startedBy = intent.getStringExtra(STARTED_BY);
Log.i(TAG, "Was bound to by: " + startedBy);
// allow binding to this local service directly so anyone can call public functions on this service directly
return binder;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment