Search code examples
androidandroid-jetpack-composeandroid-jetpackandroid-preferences

Not able to find "extra" attribute in jetpack preference in Android


Am trying to build Settings kind of App, I choose to use Preferences to build UI . I am using jet pack preferences (androidx.preference.Preference) , If I want to launch fragment with some extras ,can use below with normal preference .

   <com.android.xyz.ItemsTextPreference
  android:key="xyz"
  android:title="Fragment One"
  android:visibility="invisible"
  android:fragment="com.android.xyz.MyFragment"
  <extra android:name="one" android:value="first fragment" />
</com.android.xyz.ItemsTextPreference>

But in Jetpack preference , there is no "extra" attribute .

Any alternative way to send extra from preference view ?


Solution

  • I found solution , earlier my Preference screen having only below schema, which is from jetpack.

     <PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
    

    After adding one more schema from traditional preference from android, like below .

    <PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:android="http://schemas.android.com/apk/res/android">
    

    I can use combo to achieve result .

    <com.android.xyz.ItemsTextPreference
        android:key="xyz"
        android:title="Fragment One"
        app:isPreferenceVisible="false">
       <extra android:name="one" android:value="first fragment" />
    </com.android.xyz.ItemsTextPreference>