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

后端 未结 3 1967
旧巷少年郎
旧巷少年郎 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:39

    I was pretty sure onPause() would be called when such events happen, but it seems to be wrong... or is it me?

    onPause() will be called if another activity takes over foreground input. So, if a third-party app came to the foreground, even with a dialog-themed activity, onPause() would be called.

    There is no requirement for onPause() to be called from OS components, though.

    I'd preferably not hook on each system broadcast action individually, since I'd like to be as generic as possible (and react to ANYTHING that hides my Activity).

    What you want is not possible. Not all of the things you list have broadcast Intents, and there are other techniques that people can use (e.g., Toasts) that will obscure part of your activity of which you will have no knowledge.

提交回复
热议问题