Created
July 17, 2025 08:14
-
-
Save s3va/6fd37b6f34786a266a8b49fbe8f49d5e to your computer and use it in GitHub Desktop.
Coroutine Scope of Service (or something like this).
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
| class YourService : Service() { | |
| private val job = SupervisorJob() | |
| private val scope = CoroutineScope(Dispatchers.IO + job) | |
| fun foo() { | |
| scope.launch { | |
| // Call your suspend function | |
| } | |
| } | |
| override fun onDestroy() { | |
| super.onDestroy() | |
| job.cancel() | |
| } | |
| } | |
| // https://stackoverflow.com/a/63407811/11798617 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment