Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: If an element is deprecated at a certain API level, is it only for that API level and above?

If an element was deprecated in API level 11, is it considered a deprecated element (not to be used if it can be helped) in API levels below 11 also or just 11 and above? If I am writing an app for API level 8, should I care about an element that was deprecated in API level 11?

This is slightly confusing to me. In Android API, for the SQLiteDatabase class for example, the method setLockingEnabled(boolean lockingEnabled) says: This method was deprecated in API level 16. This method now does nothing. Do not use.

Does that mean it does nothing for all API levels below also or just API level 16 and above?

And if you are working on professional, commercial software, how important is it to avoid deprecated elements?

like image 207
Ci B Avatar asked Dec 20 '22 04:12

Ci B


2 Answers

If an element was deprecated in API level 11, is it considered a deprecated element (not to be used if it can be helped) in API levels below 11 also or just 11 and above?

Just 11 and above.

If I am writing an app for API level 8, should I care about an element that was deprecated in API level 11?

"Deprecated" in Android usually means "we think that there is a better solution that you should consider, but we will support this old approach as best we can as long as we can". While you should endeavor to stop using deprecated methods, that's not something you should panic about and drop everything to address right away, and often times you need the deprecated materials for older Android OS levels, before they were deprecated.

Does that mean it does nothing for all API levels below also or just API level 16 and above?

Since they said "now does nothing", it is safe to say that it did something (non-nothing?) previously.

And if you are working on professional, commercial software, how important is it to avoid deprecated elements?

In the specific case of this method, I'd skip using it, though that's more due to the nature of this method.

As a counter-example, the way preference screens are set up differs substantially in API Level 11+ (PreferenceFragment and PreferenceActivity) versus before (PreferenceActivity alone). You can't avoid the deprecated element on older devices, simply because there is no viable alternative (e.g., backport of PreferenceFragment).

like image 176
CommonsWare Avatar answered Apr 27 '23 04:04

CommonsWare


From the Docs

Annotation type used to mark program elements that should no longer be used by programmers. Compilers produce a warning if a deprecated program element is used.

I would suggest trying not to use them at all when possible. When you do I would take into consideration that this object, method, etc...may not work at some point in the future. When you build an app you typically want to build it so it can be easily maintained and flexible in the future. For this reason, I wouldn't use them if not necessary and there is almost always another way to do something

like image 22
codeMagic Avatar answered Apr 27 '23 03:04

codeMagic