I would like to start an Activity from a default preferences.xml, with < intent > tag. The Activities are well tested, the problem is not with that. (I'm extending PreferenceActivity in my app, so the preferences.xml is "comes" with that) Please look at the code, what's wrong?
preferences.xml:
....
<PreferenceCategory
android:title="@string/titleEtcSetup">
<PreferenceScreen
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" />
</PreferenceScreen>
.....
</PreferenceCategory>
.....
manifest.xml:
....
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.notifier.ui"....
....
<activity android:name=".EditCoursesNamesActivity" android:label="@string/titleRenameCourses">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
.....
The Activity isn't calling when I press the "renameCourses item", nothing happens. The LogCat is "clear", no errors or warnings. I was searching a lot, and I didn't find a solution, maybe I just missed something... Please help!
I solved the same issue by declaring the
<intent-filter>
in the manifest as follows:I was having the same issue. and solve by this
androidManifest.xml
and in Preference:
This solution shows you how to wire in an activity into your preferences headers.
First, your target activity must be declared in the manifest like this:
Notice here that the android:name for the activity and action are the same.
Now in your preferences.xml file you need only to declare a header like this:
And that's all there is to it.
Caution! The value of
targetPackage
should be the package id of the app, as declared in the root element of yourAndroidManifest.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).targetPackage and targetClass(prefix) may differ because of refactoring package name. Easy way to check it you can delete activity in manifest and call
startActivity()
then you will see this error in logCat: "Unable to find explicit activity class {'targetPackage'/'targetClass'}". Those are the right names you should write into Preference>intent. Intent-filter is not needed.I was having the same issue. I got this working by only declaring the action in my AndroidManifest.xml, as such:
Then in my Preferences xml file: