如何处理应用程序被HOME按钮最小化最小化、如何处理、应用程序、按钮

2023-09-07 04:44:56 作者:孤靈ゞ

几天前出现了一个问题.我有一个监听 GPS 位置的应用程序.监听器是一个一直工作的后台服务,该服务将数据保存在应用程序级别,每个活动都会读取这些数据.因此,当我按下后退按钮时,我能够捕捉到此事件并且我可以停止服务,但是当我按下 HOME 按钮时,服务仍在工作,尽管应用程序处于后台模式并且这会消耗电池,因为 GPS 始终工作.我该如何处理这个事件?我确实想在用户按下 HOME 按钮时停止所有服务,并在用户回来时再次启动它们.10 倍

An issue has appeared a few days ago. I have an application that listen for GPS location. The listener is a background service that works all the time, this service saves data in application level and each activity reads this data. So, when i press back button i am able to catch this event and i can stop the service, but when i press HOME button the service is still working although the application is in background mode and this consumes battery, because the GPS always works. How can i handle this event? I do want to stop all services when the user presses HOME button and start them again when user gets back. 10x

推荐答案

您无法在 Android 应用程序中处理主页按钮事件.Google 已将其仅供内部使用.

You can not handle home button events in your Android application. Google has made it for internal use only.

LINK 1链接2