安卓:检测当另一个活动启动(或您的活动失去焦点) [英] Android: Detect when another Activity is launched (or your activity loses focus)

查看:99
本文介绍了安卓:检测当另一个活动启动(或您的活动失去焦点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像标题所说,我需要检测的时候,我的应用程序失去焦点,因为其他应用程序启动(电话进来,或者用户点击主页等)。

Like the title says, I need to detect when my app loses focus because another app is launched (Phone call comes in, or user hits Home etc).

重写Activity.OnStop不起作用,因为这是在我的应用程序切换活动时,称为均匀。

Overriding Activity.OnStop does not work because that is called even when switching activities within my app.

推荐答案

我相信你可以使用:

onWindowsFocusChanged(布尔hasFocus)

onWindowsFocusChanged(boolean hasFocus)

这是你的活动。

这篇关于安卓:检测当另一个活动启动(或您的活动失去焦点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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