Reputation: 360
Is there a difference between:
<!--1.-->
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<!--2.-->
<uses-permission android:name="android.permission.CAMERA"/>
Because using the different versions in Android Studio the 1. option has a yellow background. So does it have any affect on the code?
Upvotes: 3
Views: 206
Reputation: 4118
No there is not. While the closing of XML tag is necessary it can be done in two ways:
Non-Empty Closed Element with
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
Empty Closed Element
<uses-permission android:name="android.permission.CAMERA"/>
Advantages of Empty Closed Elements:
Disadvantages of Empty Closed Elements:
Note that the Android Studio shows it in yellow because it know that the self-closing elements need not be added whenever there are no children for the element.
But in case if you have children, the closing tag is required.
Upvotes: 2
Reputation: 3409
No there is no difference.
The second tag is called a self closing tag and is treated equivalently by the XML parser. It's simply a shortcut for when an element has no child elements.
It shows up in yellow because self closing tags are easier to read and Android Studio wants you to implement good coding practices :P.
When your tag needs to add children though, then you can't 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-->
Upvotes: 7