Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between uses-permission

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?

like image 529
Adrian Avatar asked Jan 27 '26 12:01

Adrian


1 Answers

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.

like image 169
xyz Avatar answered Jan 30 '26 02:01

xyz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!