2010-09-16 69 views
5

我是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标志。这 真的是你想要的吗?

(全Logcat on pastebin

这里的清单,其中活动性被定义的一部分:

<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表达的位;)

回答

7

我有同样的问题,刚刚发现,如果你改变自己的喜好:

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
<PreferenceCategory android:title="@string/pref_cat_general"> 
</PreferenceCategory> 
    <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> 
</PreferenceScreen> 

然后,它按预期工作。这很奇怪,因为我希望PreferenceCategory将项目分组为它的子项......并且为什么会导致这种不相关的(?)错误?

+0

谢谢你的回答!我正在将最后几周搬到新的公寓,直到今天才离线。 这个解决方案就像是一种解决方法,但是谢谢,现在一切运行良好。 – Esentian 2010-10-08 15:46:11

+2

上帝该死的,哦,Android,只需通过删除它终于工作。非常感谢你! – Defuera 2014-09-26 12:38:37

+0

它不适合我。 PreferenceScreen不显示它是否在PreferenceCategory之外。 – 2016-07-13 10:05:01

相关问题