0

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 ?

Karan Mehta
  • 1,442
  • 13
  • 32
  • Found a similar question in this [post](https://stackoverflow.com/questions/2082640/is-there-any-way-to-put-extras-to-intent-from-preferences) – N-RAYAN Feb 17 '22 at 09:21

2 Answers2

0

try to wrap your extra attribute inside the intent attribute something like this:

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

</com.android.xyz.ItemsTextPreference>
Dharman
  • 30,962
  • 25
  • 85
  • 135
N-RAYAN
  • 123
  • 1
  • 1
  • 8
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 17 '22 at 12:51
  • This works with traditional preference , not with jetpack preference ,jetpack not supporting extra attribute . This code gave compilation error . – Saikumar S Feb 17 '22 at 13:55
0

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>