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(
@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