On Android, how to detect a system dialog is displayed (power options, recent apps, low battery…)?

后端 未结 3 1971
旧巷少年郎
旧巷少年郎 2020-12-16 21:37

Hi Stackoverflowers (I know, that doesn\'t sound like it should...)

Well I think It\'s almost all in the question: I\'d like to catch anything that causes the displa

3条回答
  •  粉色の甜心
    2020-12-16 22:15

    The best solution I have come to this so far is to implement in your activity onWindowFocusChanged

    https://developer.android.com/reference/android/app/Activity#onWindowFocusChanged(boolean)

    In Kotlin:

        override fun onWindowFocusChanged(hasFocus: Boolean) {
            super.onWindowFocusChanged(hasFocus)
            if (!hasFocus) {
                //todo your logic
            }
        }
    

    Since this can be called a lot of times you can debounce this event when showing an animation

提交回复
热议问题