I’m looking to write preferences that can be applied to both 3.0 and pre-3.0 devices. Discovering that PreferenceActivity contains deprecated methods (although these are used in the accompanying sample code), I looked at PreferenceFragement and the compatibility package to solve my woes.
It appears, though, that PreferenceFragment isn’t in the compatibility package. Can anyone tell me whether this was intentional? If so, can I easily target a range of devices (i.e. < 3.0 and >=3.0) or will I have to jump through hoops? If it wasn’t intentionally excluded, can we expect a new release of the compatibility package? Or is there another workaround that is safe to use?
The deprecated methods are deprecated as of Android 3.0. They are perfectly fine on all versions of Android, but the direction is to use
PreferenceFragmenton Android 3.0 and higher.My guess is it’s a question of engineering time, but that’s just a guess.
I consider it to be done “easily”. Have two separate
PreferenceActivityimplementations, one using preference headers andPreferenceFragments, the other using the original approach. Choose the right one at the point you need to (e.g., when the user clicks on the options menu item). Here is a sample project demonstrating this. Or, have a singlePreferenceActivitythat handles both cases, as in this sample project.You will find out when the rest of us find out, which is to say, if and when it ships.
See above.