onPause not fired when home button is pressed

给你一囗甜甜゛ 提交于 2019-12-10 18:07:48

问题


I have an Android AppCompatActivity that fails to fire onPause event when the Home button is pressed. According to the Android documentation:

The system calls this method as the first indication that the user is leaving your activity (though it does not always mean the activity is being destroyed);

However, whenever I am in the AppCompatActivity, onPause does not fire when Home button is pressed. Otherwise it fires as expected for back button or normal close of the AppCompatActivity.

I have rebooted the test device with status quo.

I am handling the event as such:

@Override
protected void onPause() {
   super.onPause();
   Log.d(TAG, "onPause - Test");
}

The following event fires with the Home button:

@Override
protected void onUserLeaveHint()
{
    Log.d(TAG,"onUserLeaveHint - Test");

}

However, I cannot do anything but log to console, all other actions are ignored.

Edit

I think this is related. When I do press the Home button, the following exception is thrown:

WindowState: WIN DEATH: Window{7d162a0 u0 com.test.myapp/com.test.myapp.TestActivity}

Which is what happens when an ANR forced kill is executed

来源:https://stackoverflow.com/questions/50379584/onpause-not-fired-when-home-button-is-pressed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!