Android - is there a callback that gets called rig

2019-02-06 03:38发布

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条回答
疯言疯语
2楼-- · 2019-02-06 04:08

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.
查看更多
登录 后发表回答