How To Find A Replacement For Deprecated Method?
Solution 1:
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/
Solution 2:
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.
Post a Comment for "How To Find A Replacement For Deprecated Method?"