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