Skip to content

Instantly share code, notes, and snippets.

@samhorne
Created July 19, 2022 15:43
Show Gist options
  • Save samhorne/5a9b0abbab060ada779c70fc77aede53 to your computer and use it in GitHub Desktop.
Save samhorne/5a9b0abbab060ada779c70fc77aede53 to your computer and use it in GitHub Desktop.
Android check if app in foreground or background
fun printProcessInfo(){
val myProcess = RunningAppProcessInfo()
ActivityManager.getMyMemoryState(myProcess)
val isInBackground = myProcess.importance != RunningAppProcessInfo.IMPORTANCE_FOREGROUND
Log.i("activitystate", "isInBackground: $isInBackground")
Log.i("activitystate", "Process: ${myProcess.importance}")
}
@timothy
Copy link

timothy commented Jul 19, 2022

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment