Android DialogFragment生命周期show->onCreateView

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

1
2
mActivityDialogFragment.show(((FragmentActivity) mActivity).getSupportFragmentManager(), "dialog");
mActivityDialogFragment.setDialogBackground(url);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@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();
}
}

输出日志

1
2
3
4
ActivityDialogFragment.show
ActivityDialogFragment.setDialogBackground
ActivityDialogFragment.onCreateView
ActivityDialogFragment.onViewCreated

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :