简体   繁体   English

Android URI类-它的作用是什么?

[英]Android URI Class - What is it used for?

I read the definition of the URI class here and here , but I'm still not sure how I would use an URI object in a android project since the second answer does not address URI in its specific use cases. 我在这里这里阅读了URI类的定义,但是我仍然不确定如何在android项目中使用URI对象,因为第二个答案在其特定用例中并未解决URI。 Does anyone have a better insight on what an URI object can be used for? 是否有人对URI对象的用途有更好的了解? In what kinds of circumstances should I instantiate an URI object? 在哪种情况下应该实例化URI对象? When is an URI object useful and why should I create one? URI对象什么时候有用,为什么我应该创建一个? It would be helpful to have a concrete example. 举一个具体的例子会有所帮助。 Below is an example I found by creating a blank dialog via Android Studio (factory method provided when one creates). 以下是通过Android Studio创建空白对话框(创建时提供的工厂方法)的示例。

    public void onButtonPressed(Uri uri) {
    if (mListener != null) {
        mListener.onFragmentInteraction(uri);
    }

or 要么

    public interface OnFragmentInteractionListener {
    void onFragmentInteraction(Uri uri);
    }

If the examples above are not helpful you could use your own explanation as when a developer should consider creating an URI object. 如果上面的示例没有帮助,您可以使用自己的解释,例如开发人员应考虑创建URI对象时。 Thanks. 谢谢。

@ CBA110,您可以将URI视为您的android系统中的本地地址。由于我已经使用过Contacts URI,因此我是这样考虑的.Contacts URI是通讯录数据库,如果您要从该数据库查询任何联系人,则需要使用此通讯录URI用作您的android手机/系统中的本地地址,并检索您需要的联系人。如果您不理解,请不要挖掘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM