安卓:检测当另一个活动启动(或您的活动失去焦点)
问题描述:
就像标题所说,我需要检测的时候,我的应用程序失去焦点,因为其他应用程序启动(电话进来,或者用户点击主页等)。
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)
这是你的活动。