During the initialization of Gaud map, a bundle object of savedInstanceState is needed. The first button knife is used in the project. This is how I encapsulate the base class. There is no problem
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
if (null != rootView) {
ViewGroup parent = (ViewGroup) rootView.getParent();
if (null != parent) {
parent.removeView(rootView);
}
} else {
int layout = getContentView();
rootView = inflater.inflate(layout, container, false);
}
this.mContext = getActivity();
ButterKnife.bind(this, rootView);
savedstanceState(savedInstanceState);
if (useEventBus()) {
EventBusUtils.register(this);
}
refWatcher = BaseApplication.getRefWatcher(getActivity());//leakcanary tool to detect memory leaks in ondestore
return rootView;
}
The project uses kotlin. Because kotlin has its own extension, it doesn't need butterKnife, so it cancels butterKnife, thus encapsulating the following
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// if (null != rootView) {
// val parent = rootView?.parent as ViewGroup
// parent.removeView(rootView)
// } else {
// }
val layout = getContentView()
rootView = inflater.inflate(layout, container, false)
this.mContext = context
savedstanceState(savedInstanceState)
if (useEventBus()) {
EventBusUtils.register(context)
}
//leakcanary tool to detect memory leaks in ondestore
refWatcher = LibApplication.getRefWatcher(context)
return rootView
}
open fun savedstanceState(savedInstanceState: Bundle?) {}
protected abstract fun initData()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
isViewPrepare = true
initDialog()
initView(view)
initData()
lazyLoadDataIfPrepared()
}
At this time, the pit will come. After that, configure the map
override fun savedstanceState(savedInstanceState: Bundle?) {
mapView?.onCreate(savedInstanceState)
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView?.onSaveInstanceState(outState)
}
No doubt about the base class at first
Later, I saw the following base class. savedstanceState(savedInstanceState) should not be placed under onCreateView(), but under onViewCreated()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
isViewPrepare = true
initDialog()
initView(view)
savedstanceState(savedInstanceState)
initData()
lazyLoadDataIfPrepared()
}
So it can be used, and the problem can be solved