Best practice for instantiating a new Android Fragment

前端 未结 13 1481
暖寄归人
暖寄归人 2020-11-21 04:38

I have seen two general practices to instantiate a new Fragment in an application:

Fragment newFragment = new MyFragment();

and

<         


        
13条回答
  •  醉话见心
    2020-11-21 05:11

    Best way to instantiate the fragment is use default Fragment.instantiate method or create factory method to instantiate the the fragment
    Caution: always create one empty constructor in fragment other while restoring fragment memory will throw run-time exception.

提交回复
热议问题