Last active
October 30, 2018 14:52
-
-
Save soygul/dc9798853191ed5ed766 to your computer and use it in GitHub Desktop.
Android local service binding - code snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************* | |
* 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