如何通过HOME按钮最小化应用程序 [英] How to handle that the application is minimized by HOME button

查看:115
本文介绍了如何通过HOME按钮最小化应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前出现了一个问题. 我有一个监听GPS位置的应用程序.侦听器是始终运行的后台服务,此服务将数据保存在应用程序级别,并且每个活动都读取该数据.因此,当我按下后退"按钮时,我可以捕获此事件,并且可以停止该服务,但是当我按下主页"按钮时,该服务仍在工作,尽管该应用程序处于后台模式,并且这会消耗电池电量,因为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

这篇关于如何通过HOME按钮最小化应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆