我想要从带有< preferences.xml >标记的默认意图开始一个活动。这些活动都经过了很好的测试,问题不在于此。(我在我的应用程序中扩展了PreferenceActivity,所以preferences.xml是“附带的”)请看代码,有什么问题吗?
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>
.....
当我按下"renameCourses item“时,活动没有调用,什么也没有发生。LogCat是“清晰的”,没有错误或警告。我寻找了很多,但我没有找到解决方案,也许我只是错过了什么……请帮帮我!
发布于 2012-05-04 09:58:36
我也有同样的问题。我只需在我的AndroidManifest.xml中声明该操作,就可以实现这一点:
<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>
然后在我的首选项xml文件中:
<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>
发布于 2011-09-02 04:09:45
我相信<intent>
标签必须在<Preference>
中,而不是<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>
发布于 2013-05-18 08:07:37
注意!Gradle的值应该是应用程序的包id,正如在AndroidManifest.xml
文件(在Gradle build文件中定义)的根元素中声明的那样。它不一定与Activity类的Java包相同(人们通常将它们放在"ui"
的子包中)。
因此,在您的特定情况下,我打赌targetPackage
应该是"my.notifier"
,而不是"my.notifier.ui"
(我必须查看清单才能确定)。
https://stackoverflow.com/questions/7275015
复制相似问题