According to the Android API documentation, Activity.onRetainNonConfigurationInstance() has been deprecated in favor of Fragment.setRetainInstance().
However, I have run into two separate situations where Fragment.setRetainInstance() doesn't seem to be feasible to use.
If the Fragment contains a WebView. According to Diane Hackborne, 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 WebView.saveState() and WebView.restoreState() to restore the web view state.
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:
java.lang.IllegalArgumentException: No view found for id 0x7f060091 for fragmentThis 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.
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 Fragment.setRetainInstance(), and there is no Fragment.onRetainNonConfigurationInstance(), what is the best approach to take?