showDialog()、onPrepareDialog()和onCreateDialog()的关系

showDialog()调用createDialog()和onPrepareDialog(),其中createDialog()调用onCreateDialog()。

 

Android SDK 源代码:

public final void showDialog(int id) {
        showDialog(id, null);
}

==================================================================================================

public final boolean showDialog(int id, Bundle args) {
        if (mManagedDialogs == null) {
            mManagedDialogs = new SparseArray<ManagedDialog>();
        }
        ManagedDialog md = mManagedDialogs.get(id);
        if (md == null) {
            md = new ManagedDialog();
            md.mDialog = createDialog(id, null, args);
            if (md.mDialog == null) {
                return false;
            }
            mManagedDialogs.put(id, md);
        }
       
        md.mArgs = args;
        onPrepareDialog(id, md.mDialog, args);
        md.mDialog.show();
        return true;
}

==================================================================================================

 private Dialog createDialog(Integer dialogId, Bundle state, Bundle args) {
        final Dialog dialog = onCreateDialog(dialogId, args);
        if (dialog == null) {
            return null;
        }
        dialog.dispatchOnCreate(state);
        return dialog;
}

你可能感兴趣的:(dialog)