title: Unable to use Fragment.setRetainInstance() as a replacement for Activity.onRetainNonConfigurationInstance()
body: <p>According to the Android API documentation, <a href="http://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance%28%29" rel="noreferrer">Activity.onRetainNonConfigurationInstance()</a> has been deprecated in favor of <a href="http://developer.android.com/reference/android/app/Fragment.html#setRetainInstance%28boolean%29" rel="noreferrer">Fragment.setRetainInstance()</a>.</p>
  
  <p>However, I have run into two separate situations where Fragment.setRetainInstance() doesn't seem to be feasible to use.</p>
  
  <ol>
  <li><p>If the Fragment contains a WebView. According to <a href="https://groups.google.com/d/msg/android-developers/cWnxkQ8RLeY/RA1n77EDeR8J" rel="noreferrer">Diane Hackborne</a>, you cannot re-use a WebView across configuration changes. Which I guess means that you need to allow the Fragment to tear-down and re-create the WebView when the screen rotates, and use <a href="http://developer.android.com/reference/android/webkit/WebView.html#saveState(android.os.Bundle)" rel="noreferrer">WebView.saveState()</a> and <a href="http://developer.android.com/reference/android/webkit/WebView.html#restoreState(android.os.Bundle)" rel="noreferrer">WebView.restoreState()</a> to restore the web view state.</p></li>
  <li><p>If the Fragment belongs to a layout that no longer exists after the configuration change, when the FragmentManager tries to restore the Fragment, it will throw:</p>
  
  <pre><code>java.lang.IllegalArgumentException: No view found for id 0x7f060091 for fragment
  </code></pre>
  
  <p>This can occur (for example) if you have a two-fragment layout in landscape mode, but a one-fragment layout in portrait mode. When rotating from landscape to portrait, if setRetainInstance() set to true, neither Fragment gets destroyed, but one fragment no longer has a valid view to be re-attached to, hence the exception.</p></li>
  </ol>
  
  <p>So, if you're building a Fragment-based application, and you need to retain data (for example references to running AsyncTasks) between configuration changes, and you can't use <a href="http://developer.android.com/reference/android/app/Fragment.html#setRetainInstance%28boolean%29" rel="noreferrer">Fragment.setRetainInstance()</a>, and there is no Fragment.onRetainNonConfigurationInstance(), what is the best approach to take?</p>