What does "This method is deprecated" mean for application developers
Asked Answered
B

5

37

I see quite a few good old useful methods or even entire classes being "deprecated and obsolete".

But code that used to call those methods continues to work. So, what does this mean to me, as an Android applications developer?

  1. Continue using this method as long as I want, because newer SDKs will always remain backward compatible.
  2. It will work as long as I build for older targets (e.g. API 8), but if I build from API 14 up, the compiler will refuse to complete the build.
  3. Both (1) and (2)
  4. Other?

This is especially confusing when no alternatives are provided, as in the case of WebView.PictureListener.html#onNewPicture.

Bastia answered 9/12, 2011 at 17:16 Comment(1)
It means a new headache if your intentions are to cover the maximum amount of possible devices and you do not want to exclude those users having some "outdated" phones.Transistorize
L
29

It usually means that there's either a better way of doing things or that the deprecated functionality had some irreparable flaw and should be avoided. You can usually keep using deprecated methods, but you are advised to either switch to some new API (in the first case) or find some other way of doing what you want (in the second).

Regarding onNewPicture in particular, the entire PictureListener interface is deprecated. There's no sign of what, if anything, is supposed to replace it. A comment by @CommonsWare in this thread is food for thought:

It is conceivable that upstream changes in WebKit are driving the deprecation and that support for PictureListener might be totally lost in some future release.

Lengthwise answered 9/12, 2011 at 17:21 Comment(3)
What you (and others) say makes sense, but it's very difficult to understand this when no alternative or a better way is suggested where the laconic "This method is deprecated. This method is now obsolete." is found in the docs.Bastia
@Bastia - I agree that this case is difficult. See the second part of my answer, which I see I added at exactly the same second you posted your comment.Lengthwise
Thanks for the link to CommonsWare's comment. I bet onNewPicture has been deprecated due to the trend of websites abusing Javascript by sending hundreds of updates per second to deliver scrolling ads...Bastia
H
13

I would go with 4:

It will basically tell you that the use of the method or class is discouraged; it is NOT 100% that they will keep backward compatibility (they can decide to not include that method in future releases), so you should try to use the replacement of the method or class. This is sometimes not possible to use the new methods (for instance, if you want to support devices running older versions).

Some other times it is actually possible. For instance, the showDialog method is now deprecated and they recommend to use DialogFragment class. You can achieve that even in older versions of Android by using the compatibility library.

Hypotaxis answered 9/12, 2011 at 17:19 Comment(2)
Thanks. I am a binary guy (1 or 0), so I don't really understand concepts like "discouraged", "not 100%", "sometimes", and "try to use replacement" when there is no replacement. I am confused. +1 nevertheless. :)Bastia
Usually, when you see a deprecated method it will tell you what other method you should use. Refer to the showDialog example above.Hypotaxis
C
8

Deprecated methods are not guaranteed to remain backwards compatible. They might remain in there for a few more releases just to give everyone a chance to migrate away from them before the developers remove them. The fact that they're deprecated means that the developers think that there's an easier, faster, neater, or otherwise better way to do whatever that class or method does.

It's probably better to change your code to use a non-deprecated interface now, since if you wait and it does get removed, your users will see crashes and errors.

Chamorro answered 9/12, 2011 at 17:20 Comment(0)
N
3

Even when they are deprecated, they may compile but not work. Google has decided to delete various functionality at the low OS level.

Case in point. Google, at android release 2.3 deprecated many but not all method API's that allowed call recording. They compile OK but do not function since Android 2.3 and forward on any android phone device, or tablet with phone capabilities.

Nutt answered 2/6, 2013 at 18:39 Comment(0)
G
2

As an example for a deprecated interface that has been removed in a later API level, consider the org.apache.http package: It has been deprecated in API level 22 and removed in API level 23.

Of course on actual Android devices, the classes contained in that package will still be available in the system libraries (otherwise, applications targeting an older Android release would no longer run on that device).

They are however not available in the SDK anymore, so compilation will fail unless you either change the target/build SDK to an older version (or manually include the deprecated classes).

If Google were really determined to discourage use of those libraries, they could modify the implementation so that the affected classes check the target API version of the running application and complain and/or throw a runtime exception.

Greenquist answered 1/10, 2015 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.