TimothyP TimothyP - 2 months ago 7x
Android Question

Start an activity from a PreferenceScreen

I have a list of strings (stored in a database, not as a resource) and

I want to allow the user to edit this list. This is easy enough to do with a normal

but in this application that list should be part of the
user preferences

Basically it's a list of sentences the user wants to have available for use.

Since I want to provide a consistent UI, I want to add this to the preference screen:

<PreferenceScreen xmlns:android="...">
<!-- Some other categories and preferences here -->
<PreferenceScreen android:key="PREF_PDT"
android:title="Predefined Texts"
android:summary="View and edit the list of predefined texts">
<!-- Some other categories and preferences here -->

Now let's say I have a fully working
that allows me to edit the texts in the database,
what can I do so that when the user taps the 'PREF_PDT' item the
is used?

I take it I'll have to make some modifications to the

or create a custom Preference view of some kind?

Update: So just to be clear, I do not need the 'list' screen to hook into the settings,
I just need to give the users the impression that they are still in the preferences part of the application (without breaking the navigation stack of course). Otherwise they have to go to one place to edit some settings and go to another place to edit the texts. They expect to find everything under 'settings'

Update: I've renamed the question from 'Custom Preference screen to edit a list of items' as it's clear now that what I'm trying to do is launch an activity from a PreferenceScreen. sh404's answer helps but I cannot find the right syntax to refer to the Activity I want to luanch. Perhaps it's monodroid specific. (ActivityNotFoundException)


write like this:

    android:summary="summary here" >
    <intent android:action="net.hasnath.android.MyActivity"/>

If you need to pass Intent Extras:

    android:summary="summary here" >
    <intent android:action="net.hasnath.android.MyActivity">
        <extra android:name="extra_name" android:value="my_value" />
         <extra android:name="extra_2_name" android:value="my_value_2"/>

Next you'll have to declare the Activity in the AndroidManifest.xml
or you can declare the intent int he preferences screen like this:

<intent android:targetPackage="net.hasnath.android"

This way you do not have to make any changes to the AndroidManifest.