Home » Android » How does Android Studio validate XML for the preferences screen?

How does Android Studio validate XML for the preferences screen?

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have this in my XML file for my preferences screen, based on other SO answers:

<PreferenceScreen
    android:title="@string/preference_title"
    android:summary="@string/preference_summary">
    <intent
        android:action="android.intent.action.VIEW"
        android:data="mailto:">
        <extra
            android:name="android.intent.extra.SUBJECT"
            android:value="@string/email_subject"/>
        <extra
            android:name="android.intent.extra.TEXT"
            android:value="@string/email_body"/>
    </intent>
</PreferenceScreen>

Android Studio is flagging the “extra” elements as “not allowed here.”

I don’t really understand how it is validating the XML at all because there is no actual DTD.

The “extra” seems to work correctly. Or I can even use a Preference.OnPreferenceClickListener if I want to avoid the XML. I’m just wondering (a) how Android Studio is validating it, and (b) if I’m using some shady hack that won’t always work, by including the extra element.

How to&Answers: