Skip to content

Instantly share code, notes, and snippets.

@ErikHellman
Created January 16, 2018 07:09
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 ErikHellman/1d99c38a5b0103e930de166bcc019942 to your computer and use it in GitHub Desktop.
Save ErikHellman/1d99c38a5b0103e930de166bcc019942 to your computer and use it in GitHub Desktop.
class SimpleService : Service() {
companion object {
@JvmStatic fun launchService(context: Context) {
context.startService(Intent(context, SimpleService::class.java))
}
}
override fun onBind(intent: Intent?): IBinder {
return Binder()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
thread { connectToServer() }
return START_NOT_STICKY
}
private fun connectToServer() {
// Setup persistent connection to server here...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment