Created
March 22, 2020 07:11
-
-
Save iambaljeet/2e5fcf5c85c789482cb53850e32089df to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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