Is there any way to put extras to Intent from preferences? Is there any way to put extras to Intent from preferences? android android

Is there any way to put extras to Intent from preferences?


I got an answer, you can use it like this:

<Preference    android:key="xxx"    android:title="xxx"    android:summary="xxx">   <intent android:action="xxx" >         <extra android:name="xxx" android:value="xxx" />    </intent>        </Preference>


Add the preference to the preference.xml file:

<Preference android:title="user" android:key="user"/>            

And then you can use a setOnPreferenceClickListener to launch an Intent with extras.

Preference userButton = (Preference) findPreference("user");userButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {    @Override    public boolean onPreferenceClick(Preference arg0) {        Intent intent = new Intent(getActivity(), YourTargetActivity.class);        intent.putExtra(EXTRA, mUser);        startActivity(intent);        return true;    }});


There is a data field for intents described in the documentation here.

It is used in the API demo application for the XML preferences to launch an intent in the Intent Preferences example.

Related example xml from that demo in preferences.xml:

    <PreferenceScreen            android:title="@string/title_intent_preference"            android:summary="@string/summary_intent_preference">        <intent android:action="android.intent.action.VIEW"                android:data="http://www.android.com" />    </PreferenceScreen>

Maybe this approach could work for you?