Difference between use permissions

Is there any difference between:

<!--1.-->
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<!--2.-->
<uses-permission android:name="android.permission.CAMERA"/>

      

Because using different versions in Android Studio, option 1. has a yellow background. So it affects the code?

+3


source to share


2 answers


There is no difference.

The second tag is called a self-closing tag and is parsed equivalently using an XML parser. It's just a shortcut when the element has no children.

It shows up in yellow because the closing closing tags are easier to read and Android Studio wants you to implement good coding techniques: P.



If your tag needs to add children, then you cannot use the latter:

<intent-filter>
    <action android:name="android.intent.action.MAIN" /> <!--allowed here-->
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> <!--can't do it here-->

      

Read more and more .

+7


source


No no. While closing the XML tag is necessary, there are two ways to do it:

Non-empty closed element with

<uses-permission android:name="android.permission.CAMERA"></uses-permission>

      

Empty closed device

<uses-permission android:name="android.permission.CAMERA"/>

      



Benefits of empty closed elements:

  • readability
  • smaller file size

Disadvantages of empty closed members:

  • adding child tags
+2


source







All Articles