Buggly 統計出FragmentDialog 報錯
android.support.v4.app.Fragment$InstantiationException:
Unable to instantiate fragment 省略:
make sure class name exists, is public, and has an empty constructor that is
public
說FragmentDialog必須要有公開的無參構造器。
目測應該是初始化FragmentDialog的時候報錯。
除了我們自己代碼創建FragmentDialog之外,系統也會幫我們創建FragmentDialog。這也是FragmentDialog與Dialog的最大區別!
Default constructor. Every fragment must have an
empty constructor, so it can be instantiated when restoring its
activity's state. It is strongly recommended that subclasses do not
have other constructors with parameters, since these constructors
will not be called when the fragment is re-instantiated; instead,
arguments can be supplied by the caller with setArguments()
and later retrieved by the Fragment with getArguments().
所有的Fragment必須有無參的構造器,這樣在Activity恢復的時候,會去重新初始化Fragment。這個初始化操作,就是通過反射到無參構造器進行初始化的。
還有一點需要注意:FragmentDialog 傳參的時候,應該像Fragment一樣,通過setArguments()、getArguments() 進行傳參。
這也是出現Bug的原因之一。