java 不推荐使用 Activity 类型的 managedQuery(Uri, String[], String, String[], String) 方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17739900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 14:50:44  来源:igfitidea点击:

The method managedQuery(Uri, String[], String, String[], String) from the type Activity is deprecated

javaandroiddeprecated

提问by Dilshi

When I compile the following code

当我编译以下代码时

cursor = activity.managedQuery( imageUri, proj, null, null, null );

I get following warning

我收到以下警告

The method managedQuery(Uri, String[], String, String[], String) from the type Activity is deprecated

不推荐使用 Activity 类型的 managedQuery(Uri, String[], String, String[], String) 方法

The code is working fine. What should I do to avoid this?

代码工作正常。我应该怎么做才能避免这种情况?

回答by CodingIntrigue

The managedQuerymethod is deprecated, meaning it should no longer be used and there is an updated method available. The replacement for this is getContentResolver().query():

managedQuery方法已弃用,这意味着不应再使用它,并且有可用的更新方法。对此的替换是getContentResolver().query()

cursor = activity.getContentResolver().query(imageUri, proj, null, null, null);

You can normally find out why the method is deprecated, and what you should use instead, by a quick Google of the method name, or depending on how good the javadoc is it may inform you through your IDE.

您通常可以通过快速搜索方法名称或根据 javadoc 的好坏程度通过 IDE 来了解该方法为何被弃用,以及您应该使用什么来代替。

回答by Abhilasha

The above answer is very apt. I just wanted to add to this thread more info as to why managedQueryis deprecated. Hereis a nice explanation for why the managedQueryis replaced by getContentResovler().query()

楼上的回答很贴切。我只是想在这个线程中添加更多关于为什么managedQuery被弃用的信息。 是一个很好的解释,说明为什么managedQuery被替换为getContentResovler().query()