View reuse in fragments android

前端 未结 3 948
你的背包
你的背包 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:40

    @schwiz é have implemented something similar.

    I use the setRetainInstance in the fragment. on the fragment layout I have a FrameLayout placeholder where I put my webView inside.

    This webView is created programmatically on the Fragment's onCreate using the Application Context, and I do a addView(webView) on the inflated layout in onCreateView().

    webView = new WebView(getActivity().getApplicationContext());
    

    And on onDestroyView I simply remove the webView from my framelayout placeholder.

    It work really well, unless you try to play a video in fullscreen. That doesn't work because it expects an Activity Context

提交回复
热议问题