Several methods for Android to monitor home key
Several methods for Android to monitor home key
preface:
The following two methods can perfectly solve the problem of listening to the back key, home key and multi task key (the nearest task key).
1、 Use the registration broadcast to listen to the home key and multitask key
Demonstration diagram
Create a broadcast code as follows:
Register the broadcast in the oncreate() method in the activity. The code is as follows:
In that case, it's OK. This method can fully monitor the home key and multitasking key, but you can't shield the behavior of the system.
2、 Rewrite onkeydown() to listen and mask the back and home keys
Rewrite onkeydown() in activity. The code is as follows:
Add code in oncreate() in activity as follows:
Thank you for reading, hope to help you, thank you for your support to this site!