Android - is there a callback that gets called right after onResume()?

余生颓废 提交于 2019-11-29 11:26:46

问题


Is there a callback that gets always called after onResume()? I'd need that, because AFAIK, after onResume(), every View in the layout has been rendered, so I can measure their dimensions.

Thanks.


回答1:


Activity | Android Developers

protected void onPostResume ()

Since: API Level 1

Called when activity resume is complete (after onResume() has been called). Applications will generally not implement this method; it is intended for system classes to do final setup after application resume code has run.

Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.


You might also be interested in (in the same link):

public void onWindowFocusChanged (boolean hasFocus)

Since: API Level 1

Called when the current Window of the activity gains or loses focus. This is the best indicator of whether this activity is visible to the user. The default implementation clears the key tracking state, so should always be called.

Note that this provides information about global focus state, which is managed independently of activity lifecycles. As such, while focus changes will generally have some relation to lifecycle changes (an activity that is stopped will not generally get window focus), you should not rely on any particular order between the callbacks here and those in the other lifecycle methods such as onResume().

As a general rule, however, a resumed activity will have window focus... unless it has displayed other dialogs or popups that take input focus, in which case the activity itself will not have focus when the other windows have it. Likewise, the system may display system-level windows (such as the status bar notification panel or a system alert) which will temporarily take window input focus without pausing the foreground activity.

Parameters

hasFocus    Whether the window of this activity has focus.


来源:https://stackoverflow.com/questions/6965516/android-is-there-a-callback-that-gets-called-right-after-onresume

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