开发者

When should super.onResume() be called?

开发者 https://www.devze.com 2023-03-31 22:43 出处:网络
When should super.onResume(); be called, on the first line of onResume() or on 开发者_如何学Gothe last line?

When should super.onResume(); be called, on the first line of onResume() or on 开发者_如何学Gothe last line?

protected void onResume() {
    Log.i(MY_DEBUG_TAG, "On Resume");
    super.onResume();
    displayDashboard();
}


Android’s source code can tell us everything. If you check the Activity super class you can find the following lines:

protected void onResume() {
    if (DEBUG_LIFECYCLE) Slog.v(TAG, "onResume " + this);
    getApplication().dispatchActivityResumed(this);
    mCalled = true;
}

On this basis, no matter before or after it is called.


Whether or not you choose to call the super method depends upon whether you require the inherited functionality. You can often find out if you need to call the super method from Api documentation.

Sometimes you need to do something before the super method is called (ie filter an attribute or perform an action). Sometimes your code has to happen after the super method has executed.

It is very much implementation specific.


there is an example on the following link:

Android -- How to properly handle onPause/onResume methods?

0

精彩评论

暂无评论...
验证码 换一张
取 消