Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "This method is deprecated" mean for application developers

Tags:

android

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.

like image 695
an00b Avatar asked Dec 09 '11 17:12

an00b


People also ask

What happens if we use deprecated methods in Java?

The @Deprecated annotation tells the compiler that a method, class, or field is deprecated and that it should generate a warning if someone tries to use it. That's what a deprecated class or method is. It's no longer relevant.

What is the meaning of deprecated method in Java?

Annotation Type Deprecated A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. Compilers warn when a deprecated program element is used or overridden in non-deprecated code.

Is it OK to use deprecated methods android studio?

Yes you can use deprecated methods as long as the depreciated method exists in the framework. By deprecating a method the platform developers are trying to tell you that either something is wrong with the method or there is already better way for doing the task.

How can you tell if a method is deprecated?

Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API section. Then, each use of a deprecated method or API will show up as an error/warning in the Problems view.


2 Answers

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.

like image 92
Ted Hopp Avatar answered Sep 19 '22 02:09

Ted Hopp


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.

like image 29
Cristian Avatar answered Sep 20 '22 02:09

Cristian