View reuse in fragments android

前端 未结 3 1089
你的背包
你的背包 2021-02-03 13:27

I am trying to save my View states in my fragment but I am concerned I make be leaking my Activity. Here is what I am doing:

@Override
public View onCreateView(         


        
3条回答
  •  感动是毒
    2021-02-03 13:54

    I am trying to save my View states in my fragment but I am concerned I make be leaking my Activity.

    Use onSaveInstanceState() (in the fragment) and onRetainConfigurationInstance() (in the activity) for maintaining "View states" across configuration changes. I am not quite certain what other "View states" you might be referring to.

    I am concerned because I know all Views hold onto a context and I don't know if it is the Activity context or Application context if inflated from the inflater.

    Since using the Application for view inflation does not seem to work well, you should be inflating from the Activity. And, hence, the views will hold a reference to the Activity that inflated them.

提交回复
热议问题