Detect 'home button pressed' event in android service displaying a UI (similar to facebook chatheads)

前端 未结 8 1257
暗喜
暗喜 2020-12-13 09:35

In facebook chatheads, that are part of the facebook messenger app, I noticed the following behavior: As far as I can see, the chat head itself and the opened chat screen ar

相关标签:
8条回答
  • 2020-12-13 10:14

    I'm fairly sure facebook doesn't listen for home button presses, because their logic requires the chat heads to show up regardless of what app is visible, as long as it isn't facebook.

    A simple and crude way to do this would be to maintain a static flag visible in your Application singleton, and modify it from every Activity you have. In the onPause(), set it to false, and in onResume() and onCreate() set it to true.

    Then simply check the state of this flag, and act accordingly. If its true, it means your app is visible.

    You might want to add a small pause before you act on it to prevent your injected Views from flickering each time an Activity is changed.

    0 讨论(0)
  • 2020-12-13 10:15

    You can add the category HOME to your manifest file.

    0 讨论(0)
提交回复
热议问题