Skip to content

Instantly share code, notes, and snippets.

@aanandshekharroy
Created January 24, 2019 18:32
Show Gist options
  • Save aanandshekharroy/7ba16fa349dbecf7f0fc23d26aca4902 to your computer and use it in GitHub Desktop.
Save aanandshekharroy/7ba16fa349dbecf7f0fc23d26aca4902 to your computer and use it in GitHub Desktop.
var randomNumberGeneratorService: RandomNumberGeneratorService? = null
private lateinit var connection: ServiceConnection
var bounded = false
val TAG = MainActivity::class.java.simpleName
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
connection = object : ServiceConnection{
override fun onServiceDisconnected(componentName: ComponentName) {
Log.d(TAG,"Service disconnected.")
randomNumberGeneratorService = null
}
override fun onServiceConnected(componentName: ComponentName
, service: IBinder) {
Log.d(TAG, "Service connected.")
randomNumberGeneratorService = (service as RandomNumberGeneratorService.RandomNumberGeneratorServiceBinder).service
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment