Created
January 16, 2018 07:09
-
-
Save ErikHellman/1d99c38a5b0103e930de166bcc019942 to your computer and use it in GitHub Desktop.
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
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