Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Deprecated Annotation is deprecated, what's the replacement?

Deprecaated According to Official Android Documentation Deprecated itself is deprecated in API level S. So what's the replacement for Deprecated which itself is deprecated?

Edit: Added web archive link for historical reference.

like image 472
YaMiN Avatar asked Feb 24 '21 08:02

YaMiN


People also ask

How do you replace deprecated methods in Java?

If you press CTRL+left click on a method, you find the method declaration. That is where a method is created with its contents and javadoc. Javadoc for deprecated methods often include a @deprecated annotation where it mentions the new API and when it was deprecated.

What to do with deprecated methods in Android?

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.

Do deprecated APIs still work?

Starting with Android 12, the RenderScript APIs are deprecated. They will continue to function, but we expect that device and component manufacturers will stop providing hardware acceleration support over time.


Video Answer


1 Answers

It was a documentation bug. (And it has been fixed!)

The Deprecated annotation is not really deprecated.

Apparently what happened is that the source code for Deprecated contained this in its javadoc comments:

 * @apiNote
 * It is strongly recommended that the reason for deprecating a program element
 * be explained in the documentation, using the {@code @deprecated}
 * javadoc tag. 

Apparently, the {@code @deprecated} was interpreted as an @deprecated javadoc tag by the metalava tool. This caused metalava to inject the "missing" @Deprecated annotations into the ".class" files in the Android JAR file. Presumably, the injected annotation was then incorporated into the generated javadocs on the website.

Kudos to Manohar Reddy for finding the bug in the issue tracker.

You can find the fix that they made here.


For what it is worth, java.lang.Deprecated is a class that originates in the Oracle / OpenJDK Java (i.e. standard Java) class libraries. Android wouldn't / shouldn't deliberately deprecate it without a very good reason. It would create another hurdle to Java <-> Android portability.

like image 192
Stephen C Avatar answered Oct 17 '22 23:10

Stephen C