Search code examples
androidandroid-activitypreference

Launch Activity from Preference Activity causes Permission Denial Exception


I'm having a bit of a problem here. What I want to do is launch an Activity from within the PreferenceActivity. So my preference.xml which holds the preference layout looks like this:

<Preference android:title="Launch Activity" >
   <intent android:action="org.momo.SOME_ACTIVITY" />
</Preference>

The manifest is aware of the activity I want to launch..

<activity android:label="@string/app_name" android:name="SomeActivity">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />

            <action android:name="org.momo.SOME_ACTIVITY" />
        </intent-filter>
    </activity>

guess what, I'm getting a Security Exception ( Permission Denial ) when I want to launch it. Am I missing something? My understanding of intents is still a bit incomplete, yet I figured that it must work that way.

Thank you for any help!


Solution

  • Making an intent-filter seems like a slightly roundabout way of doing this. This is a simpler approach:

    <PreferenceScreen
        android:title="@string/settings.title" 
        android:summary="@string/settings.summary">
        <intent
            android:targetPackage="com.companyname.appname"
            android:targetClass="com.companyname.appname.classname"/>
    </PreferenceScreen>