Android DialogFragment生命周期show->onCreateView

DialogFragment.show显示的生命周期是:先执行show()方法,再执行onCreateView()方法,若有如下操作:

mActivityDialogFragment.show(((FragmentActivity) mActivity).getSupportFragmentManager(), "dialog");
mActivityDialogFragment.setDialogBackground(url);

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    NLog.i("yezhou", "ActivityDialogFragment.onCreateView");
    return inflater.inflate(R.layout.layout_activity_dialog, container);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    NLog.i("yezhou", "ActivityDialogFragment.onViewCreated");
    initView(view);
    GlideImageLoader.loadViewBackground(getContext(), bgUrl, mLayoutActivityDialog);
    super.onViewCreated(view, savedInstanceState);
}

public void setDialogBackground(String url) {
    NLog.i("yezhou", "ActivityDialogFragment.setDialogBackground");
    //GlideImageLoader.loadViewBackground(getContext(), bgUrl, mLayoutActivityDialog);  //mLayoutActivityDialog空指针异常
    bgUrl = url;
}

@Override
public void show(FragmentManager manager, String tag) {
    NLog.i("yezhou", "ActivityDialogFragment.show");
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        if (manager.isDestroyed())
            return;
    }
    try {
        super.show(manager, tag);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

输出日志

ActivityDialogFragment.show
ActivityDialogFragment.setDialogBackground
ActivityDialogFragment.onCreateView
ActivityDialogFragment.onViewCreated
上一篇 RecyclerView GridLayoutManager实现复杂的列数变化的布局
下一篇 Android插件化之startActivity hook实现登录拦截
目录
文章列表
1 微信支付:获取沙箱密钥失败,确认交易密钥是否正确
微信支付:获取沙箱密钥失败,确认交易密钥是否正确
2
Dubbo Spring Cloud 服务消费方开发步骤
Dubbo Spring Cloud 服务消费方开发步骤
3
Groovy代码示例 - 文件操作
Groovy代码示例 - 文件操作
4
将文本转为二维码图片Base64编码
将文本转为二维码图片Base64编码
5
Android获取系统语言(兼容7.0)
Android获取系统语言(兼容7.0)
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。