How to find a replacement for deprecated method?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 16:15:36

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.

In addition to the javadoc information can also be found in the reference at developer.android.com.

Live example: the Camera class. At the end of the class javadoc it has this:

/**
 * (other declarations, and last)
 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
 *             applications.
 */

There you also get a link to the new alternative. If you check the reference at developer.android.com you can also see when it was deprecated (API) and (if you have a new class) you can see when that was introduced. Android has a lot to manage when it comes to API's and what was introduced when especially considering there is a new API each year.


As for the Javadoc solution, it can be followed as far as you want. If you have class X, but class X is deprecated. There is a javadoc link to class Y, which replaces class X. For some reason class Y is also deprecated. But there is a javadoc link there that leads to class Z.

Above was a basic example of how you can find the newest replacements, even though the replacement for class X is deprecated. Something to keep in mind in ANdroid programming though, is the fact that you may need the deprecated methods to support lower versions on Android.

Use setAudioAttributes(AudioAttributes) instead of setAudioStreamType().

You can see these details in the Android Developer documentation.

https://developer.android.com/reference/android/media/MediaPlayer.html#setAudioStreamType(int)

To follow the latest changes, you can check the Android Developer blog: https://android-developers.googleblog.com/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!