Created
July 19, 2022 15:43
-
-
Save samhorne/5a9b0abbab060ada779c70fc77aede53 to your computer and use it in GitHub Desktop.
Android check if app in foreground or background
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
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}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!