Android: Start Activity from preferences.xml Android: Start Activity from preferences.xml android android

Android: Start Activity from preferences.xml


I was having the same issue. I got this working by only declaring the action in my AndroidManifest.xml, as such:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.example.myapp" android:versionName="1.3" android:versionCode="4">...    <activity android:name=".activities.MyActivity"               android:label="@string/my_activity_title"              android:theme="@android:style/Theme.Black.NoTitleBar">        <intent-filter>           <action android:name="com.example.myapp.activities.MyActivity" />           <category android:name="android.intent.category.DEFAULT" />       </intent-filter>    </activity>

Then in my Preferences xml file:

<PreferenceCategory        android:title="@string/my_activity_title">    <PreferenceScreen        android:title="@string/my_activity_title"         android:summary="@string/my_activity_title">        <intent android:action="com.example.myapp.activities.MyActivity"/>    </PreferenceScreen></PreferenceCategory>


I believe <intent> tag must be inside <Preference>, not <PreferenceScreen>.

<PreferenceCategory     android:title="@string/titleEtcSetup">    <Preference        android:key="renameCourses"        android:title="@string/titleRenameCourses"        android:summary="@string/textRenameDisplayedCoursesNames">        <intent             android:action="android.intent.action.VIEW"             android:targetPackage="my.notifier.ui"             android:targetClass="my.notifier.ui.EditCoursesNamesActivity" />             </Preference>.....</PreferenceCategory>


Caution! The value of targetPackage should be the package id of the app, as declared in the root element of your AndroidManifest.xml file (which you define in your Gradle build file). It is not necessary the same as the Java package of your Activity class (people usually put them in a subpackage of "ui").

So in your specific case, I bet you the targetPackage should be "my.notifier", not "my.notifier.ui" (I would have to see the manifest to be sure).