-
-
Save Struka9/a009f1f42cc9d33376e2809d570c183e 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
// MyStartedForegroundService.kt | |
class MyStartedForegroundService: Service() { | |
private val NOTIFICATION_ID = 12345 | |
private fun createNotification(): Notification { | |
//... | |
} | |
private fun doWork(startId: Int, url: String) { | |
startForeground(NOTIFICATION_ID, createNotification()) | |
// Let's fetch something using the url | |
stopSelf(startId) | |
} | |
override fun (intent: Intent?, flags: Int, startId: Int): Int { | |
intent?.getStringExtra("EXTRA_URL")?.let { | |
doWork(startId, it) | |
} | |
return START_REDELIVER_INTENT | |
} | |
override fun onBind(intent: Intent): IBinder? { | |
// If we don't need to support binding for the service we return a null IBinder | |
return null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment