11

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.

Community
  • 1
  • 1
matt
  • 1,947
  • 1
  • 19
  • 29
  • I'd also like to know why the `extra` elements are not allowed there. In the meantime I found some examples in the Android source code that use an `extra` element inside an `intent` in XML: [prefs_screen_correction.xml](http://androidxref.com/7.0.0_r1/xref/packages/inputmethods/LatinIME/java/res/xml/prefs_screen_correction.xml#33) or [cdma_options.xml](http://androidxref.com/7.0.0_r1/xref/packages/services/Telephony/res/xml/cdma_options.xml#49). – TechAurelian Oct 12 '16 at 13:54
  • Use `Preference` instead of `PreferenceScreen` when specifying ``. – Eugen Pechanec Oct 12 '16 at 19:54

0 Answers0