我是android开发新手。PreferenceScreen - <intent .../> - 例外 - FLAG_ACTIVITY_NEW_TASK
该项目是关于使用AbstractThreadedSyncAdapter实现AbstractAccountAuthenticator以将服务器上的某些数据与内容提供者进行同步。
我做了所有事情,同时添加帐户和同步正在运行没有任何问题。
autenticator.xml:
现在我已经尝试添加偏好屏幕仿如建议在android参考通过这样的XML(搜索AbstractAccountAuthenticator,它是有解释)
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="typeOfAuthenticator"
android:icon="@drawable/icon"
android:smallIcon="@drawable/miniIcon"
android:label="@string/label"
android:accountPreferences="@xml/account_preferences"
/>
的偏好屏幕的XML看起来是这样的:
account_preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/pref_cat_general">
<PreferenceScreen android:key="@string/pref_cat_scr_keygen" android:title="@string/pref_cat_scr_keygen_title" android:summary="@string/pref_cat_scr_keygen_summary">
<intent android:action="android.intent.action.VIEW" android:targetPackage="com.android.clean" android:targetClass="com.android.clean.KeygenAct" />
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
屏幕被提示应该是怎么回事,但这就是问题所在:当我点击PreferenceScreen时,它会导致系统崩溃(在模拟器和HTC-Desire中) 。
logcat的说:
ERROR/AndroidRuntime(18754): android.util.AndroidRuntimeException: 调用startActivity()从一个活动上下文之外 要求 FLAG_ACTIVITY_NEW_TASK标志。这 真的是你想要的吗?
这里的清单,其中活动性被定义的一部分:
<activity android:name=".KeygenAct">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
整个测试代码(这是我的必需品项目找到问题)是在googlecode找到(http://code.google.com/p/cleanproject/source/browse/)(Eclipse-Project)
谢谢你的帮助, Esentian
p.s .: keygen不是密钥生成器,它意味着更多的key_general。 inartfully表达的位;)
谢谢你的回答!我正在将最后几周搬到新的公寓,直到今天才离线。 这个解决方案就像是一种解决方法,但是谢谢,现在一切运行良好。 – Esentian 2010-10-08 15:46:11
上帝该死的,哦,Android,只需通过删除 PreferenceCategory>它终于工作。非常感谢你! – Defuera 2014-09-26 12:38:37
它不适合我。 PreferenceScreen不显示它是否在PreferenceCategory之外。 – 2016-07-13 10:05:01