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?
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-->
Read more and more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With