Skip to content

Instantly share code, notes, and snippets.

@s3va
Created June 22, 2022 14:43
Show Gist options
  • Save s3va/f3339017d64898dd53441260efc9ec20 to your computer and use it in GitHub Desktop.
Save s3va/f3339017d64898dd53441260efc9ec20 to your computer and use it in GitHub Desktop.
Checking if my service is running.
private fun isMyServiceRunning(serv: String): Boolean {
val manager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
return manager.getRunningServices(Integer.MAX_VALUE)
.any {
Log.e(TAG, "isMyServiceRunning: ${it.service.shortClassName}")
it.service.shortClassName == serv
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment