【Android4.2系统源码】Activity学习

来源:互联网 发布:洗车刷卡软件 编辑:程序博客网 时间:2024/05/21 20:03

先看看Activity继承了哪些东西:

public class Activity extends ContextThemeWrapper        implements LayoutInflater.Factory2,        Window.Callback, KeyEvent.Callback,        OnCreateContextMenuListener, ComponentCallbacks2

ContextThemeWrapper 主题包装?
来看张图:
这里写图片描述
接着是一些接口:
LayoutInflater.Factory2,Window.Callback, KeyEvent.Callback,OnCreateContextMenuListener,ComponentCallbacks2

关于Activity的onCreate

protected void onCreate(Bundle savedInstanceState) {        if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState);        if (mLastNonConfigurationInstances != null) {            mAllLoaderManagers = mLastNonConfigurationInstances.loaders;        }        if (mActivityInfo.parentActivityName != null) {            if (mActionBar == null) {                mEnableDefaultActionBarUp = true;            } else {                mActionBar.setDefaultDisplayHomeAsUpEnabled(true);            }        }        if (savedInstanceState != null) {            Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG);            mFragments.restoreAllState(p, mLastNonConfigurationInstances != null                    ? mLastNonConfigurationInstances.fragments : null);        }        mFragments.dispatchCreate();        getApplication().dispatchActivityCreated(this, savedInstanceState);        mCalled = true;    }

DEBUG_LIFECYCLE是标识生命周期,
NonConfigurationInstances在上文是这么定义的:

static final class NonConfigurationInstances {        Object activity;        HashMap<String, Object> children;        ArrayList<Fragment> fragments;        HashMap<String, LoaderManagerImpl> loaders;    }

然后是onpause

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

生命周期进入停止状态,但未杀死

关于onStop

 protected void onStop() {        if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStop " + this);        if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false);        getApplication().dispatchActivityStopped(this);        mCalled = true;    }

关于OnDestory

protected void onDestroy() {        if (DEBUG_LIFECYCLE) Slog.v(TAG, "onDestroy " + this);        mCalled = true;        // dismiss any dialogs we are managing.        if (mManagedDialogs != null) {            final int numDialogs = mManagedDialogs.size();            for (int i = 0; i < numDialogs; i++) {                final ManagedDialog md = mManagedDialogs.valueAt(i);                if (md.mDialog.isShowing()) {                    md.mDialog.dismiss();                }            }            mManagedDialogs = null;        }        // close any cursors we are managing.        synchronized (mManagedCursors) {            int numCursors = mManagedCursors.size();            for (int i = 0; i < numCursors; i++) {                ManagedCursor c = mManagedCursors.get(i);                if (c != null) {                    c.mCursor.close();                }            }            mManagedCursors.clear();        }        // Close any open search dialog        if (mSearchManager != null) {            mSearchManager.stopSearch();        }        getApplication().dispatchActivityDestroyed(this);    }
0 0
原创粉丝点击