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!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>