4

Maybe stupid question but I am developing for android 2.2 to 4.1. Can I use this functionality http://developer.android.com/reference/android/preference/PreferenceFragment.html which is available only from API 11?

or must I use old http://developer.android.com/reference/android/preference/PreferenceActivity.html which has some deprecated methods.

Will old API works well on android 4.1?

senzacionale
  • 20,448
  • 67
  • 204
  • 316

2 Answers2

7

PreferenceFragment will not work on 2.2 and 2.3 (only API level 11 and above). But above versions can use the older one. So you could just go with the old PreferenceActivity - deprected methods just mean that they should be avoided, but they usually still works.

CommonsWare have before wrote, that to offer the best experience for the user and still support version 2.2, you should implement two PreferenceActivity classes and then decide at runtime which one to invoke. This can be done by checking Build.VERSION.SDK_INT and compare against '11'.

See the accepted answer here for implementation: PreferenceActivity Android 4.0 and earlier

Community
  • 1
  • 1
Thomas
  • 1,563
  • 3
  • 17
  • 37
  • Thank you. So you suggest me to use API 8 or solution from the link. Which one dou you prefer? – senzacionale Nov 29 '12 at 09:58
  • My humble opinion: It's extra work, so depends on your application. But if it's going to be released to public, then the solution from the link. This will follow standards and conventions so users will feel more comfortable. Hope it makes sense :) – Thomas Nov 29 '12 at 10:21
0

yes you can use. right click on project --> select properites --> click on android --> select any target .. any higher version google taget can run in lower version i.e, classes can be imported.. but it may possible to throw the exception if lower version wont support the class ...

Sandeep P
  • 4,291
  • 2
  • 26
  • 45
  • hmm are you sure. Thomas said different as you said now? If i select API 8 i can run it in android 4.1. But if i use API level 14 i can not use it in android 2.2 So what is best. To use API 8? – senzacionale Nov 29 '12 at 09:52