6

我是android开发的新手。

该项目是关于使用 AbstractThreadedSyncAdapter 实现 AbstractAccountAuthenticator 以将服务器上的某些数据与内容提供者同步。

我做了一切,添加帐户和同步都在运行,没有任何问题。

现在我尝试通过 xml 像在 android 参考中建议的那样添加一个 Preference-Screen(搜索 AbstractAccountAuthenticator,它在那里进行了解释),如下所示:

autenticator.xml:

<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"
 />

Preference-Screen-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 说:

错误/AndroidRuntime(18754): android.util.AndroidRuntimeException: 从 Activity 上下文外部调用 startActivity() 需要 FLAG_ACTIVITY_NEW_TASK 标志。这真的是你想要的吗?

( pastebin 上的整个Logcat

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

<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

ps:keygen 不是key generator,意思是key_general。有点不自然地表达;)

4

1 回答 1

8

我遇到了同样的问题,并且刚刚发现,如果您将偏好更改为:

<?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 将项目分组为其子项......为什么它会导致这种不相关的(?)错误?

于 2010-09-20T12:08:09.590 回答