Skip to content

Instantly share code, notes, and snippets.

@iambaljeet
Created March 22, 2020 07:11
Show Gist options
  • Save iambaljeet/2e5fcf5c85c789482cb53850e32089df to your computer and use it in GitHub Desktop.
Save iambaljeet/2e5fcf5c85c789482cb53850e32089df to your computer and use it in GitHub Desktop.
/**
* Interface for getting the instance of binder from our service class
* So client can get instance of our service class and can directly communicate with it.
*/
private val serviceConnection = object : ServiceConnection {
override fun onServiceConnected(className: ComponentName, iBinder: IBinder) {
Log.d(mTAG, "ServiceConnection: connected to service.")
// We've bound to MyService, cast the IBinder and get MyBinder instance
val binder = iBinder as MyBinder
mService = binder.service
mIsBound = true
getRandomNumberFromService() // return a random number from the service
}
override fun onServiceDisconnected(arg0: ComponentName) {
Log.d(mTAG, "ServiceConnection: disconnected from service.")
mIsBound = false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment