什么时候在Android上的*窗口焦点*的变化? [英] When does the *Window focus* change in Android?

查看:714
本文介绍了什么时候在Android上的*窗口焦点*的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目,我需要捕获窗口焦点变化。我已注销的结果活动的各个阶段。当屏幕上,其结果是,如下所示:

In my project, I need to catch the Window focus change. I have logged out the results for all the stages of an activity. When the screen is on, the result is as follows:

02-17 13:50:03.898: DEBUG/InquiryInterface(3829): onCreate screen state : false
02-17 13:50:03.898: DEBUG/InquiryInterface(3829): onStart screen state : false
02-17 13:50:03.898: DEBUG/InquiryInterface(3829): onResume screen state : false
02-17 13:50:08.998: DEBUG/InquiryInterface(3829): onPause screen state : true
02-17 13:50:09.178: DEBUG/InquiryInterface(3829): onWindowFocusChanged : false
02-17 13:50:09.228: DEBUG/InquiryInterface(3829): onStop screen state : false
02-17 13:50:09.228: DEBUG/InquiryInterface(3829): onDestroy screen state : false

onWindowFocusChanged是由类活动提供的方法。和在列表中显示的值是该方法的输入值(布尔hasFocus)onWindowFocusChanged

onWindowFocusChanged is the method provided by the class Activity. And the value shown in the list is the input value(boolean hasFocus) of the method onWindowFocusChanged.

我使用了下列code得到的窗口焦点状态的方法,的onCreate,ONSTART等每一个国家。

I have used the following code to get the state of window focus for every state of the method, onCreate, onStart, etc.

@Override
    public void onResume() {
        super.onResume();
        Log.d(TAG, "onCreate screen state : "
                 +String.valueOf(this.hasWindowFocus()));
}

但在Android的机制的文档,我读:方法onResume()是调用时,活动将开始与用户交互。此时你的活动是在活动堆栈的顶部,与用户输入要它。

因此​​,在这种方式,我应该得到真为窗口焦点中onResume,但不是在的onPause()。任何人有一个想法,为什么出现这种情况?

So in this way, I should get "True" for the window focus within onResume, but not in onPause(). Anyone has an idea why this happens?

推荐答案

我对它的理解是你说的正好相反。 onResume()被调用之前您的活动获得焦点,并在onPause被调用之前就失去焦点。我可以发誓我读了这样的地方,但我似乎无法找到在那里我看到了它的的活动生命周期文档

My understanding of it is the opposite of what you say. onResume() gets called just before your activity gets focus, and onPause gets called just before it loses focus. I could have sworn I read it this way somewhere but I can't seem to find where I saw it in the Activity Lifecycle documentation

这篇关于什么时候在Android上的*窗口焦点*的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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