问题描述
我是Android编程的新手.
I am new to Android programming.
我一直在遵循有关从此网站
本教程要求使用不推荐使用的MediaPlayer
类中的setAudioStreamType
方法.哪种方法尤其可以代替此不推荐使用的方法?而且,是否有资料来源可以找到所有不赞成使用的方法及其当前替代方法?
The tutorial calls for a setAudioStreamType
method from MediaPlayer
Class which is deprecated. Which method replaces this deprecated method in particular? And, is there a source where we can find all deprecated methods and its current alternative?
这是我的代码,其中有关于不推荐使用的方法的警告:
Here is the code I have where there is a warning about a deprecated method:
public void initMusicPlayer(){
//set player properties
player.setWakeMode(getApplicationContext(),
PowerManager.PARTIAL_WAKE_LOCK);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setOnPreparedListener(this);
player.setOnCompletionListener(this);
player.setOnErrorListener(this);
}
推荐答案
如果按CTRL +左键单击某个方法,则会找到该方法的声明.这就是使用其内容和javadoc创建方法的地方.不推荐使用的方法的Javadoc通常会在@deprecated
注释中提及新的API,以及何时不推荐使用.
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.
除了javadoc信息外,还可以在developer.android.com上的参考中找到.
In addition to the javadoc information can also be found in the reference at developer.android.com.
实时示例:Camera类.在javadoc类的末尾,它具有以下内容:
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.
*/
您还可以找到新替代方法的链接.如果您在developer.android.com上检查引用,则还可以看到不推荐使用它的时间(API),并且(如果有新类的话)还可以看到引入的时间.对于API以及要特别考虑到每年都有新API时引入的内容,Android有很多需要管理的地方.
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.
对于Javadoc解决方案,只要您愿意,就可以遵循它.如果您有X类,但不推荐使用X类.有一个指向类Y的javadoc链接,它代替了类X.出于某种原因,也不建议使用类Y.但是那里有一个javadoc链接,它指向类Z.
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.
以上是一个基本示例,说明了如何找到最新的替代品,即使不推荐使用X类替代品.不过,在ANdroid编程中要记住的一点是,您可能需要弃用的方法才能在Android上支持较低版本.
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.
这篇关于如何找到不推荐使用的方法的替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!