Alex Volovoy Alex Volovoy - 1 month ago 8
Android Question

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

Hi i'm launching activity from preferences screen. Activity is shared among three preferences.
I wonder if i can set extras for this activity in xml

<Preference
android:key="action_1"
android:title="@string/action_1_title"
>
<intent
android:action="com.package.SHAREDACTION"
>

</intent>
</Preference>


i wonder if i can do something like

<extras>
<item
android:name=""
android:value=""/>
</extras>


All i need to do to pass an integer really. I can different actions and check action instead of extras.

Answer

As your extras are not constants, you should pass them in the java code instead of xml.

Intent intent = new Intent( this, YourTargetActivity.class );
intent.putExtra( EXTRAS_KEY, extras );
yourPref.setIntent( intent );