I'm trying to call an activity from a Preference item
Ideally I'd like to simply specify an explicit intent in the xml for that Preference item
but my google fu has deserted me and I can only find examples of implicit intents, e.g.
<Preference android:title="@string/prefs_web_page" >
<intent android:action="android.intent.action.VIEW"
android:data="http://www.example.com" />
</Preference>
I have already called my activity elesewhere programatically, e.g.
Intent intent = new Intent(this, FileChooserActivity.class);
but I want to call this direct from the xml
is this possible or am I barking up the wrong tree?
I believe the currently selected answer is not an explicit Intent, but an implicit one.
To make it an explicit Intent,
your preference XML should look like this (define targetPackage and targetClass):
<Preference android:title="@string/preference_title__intent_act" >
<intent
android:targetPackage="com.mycompany.mypackage"
android:targetClass="com.mycompany.mypackage.IntentActivityFromPreferences" />
</Preference>
Your activity declaration in AndroidManifest.xml should look like this:
<manifest
...
package="com.mycompany.mypackage">
...
...
<activity
android:name="com.mycompany.mypackage.IntentActivityFromPreferences"
android:label="@string/activity_intentactivityfromprefs_name">
</activity>
</manifest>
Notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With