我是Android开发的新手。

该项目旨在用AmpactrackCountauthenticator使用AbstractThreadSyncAdapter实施一个AbstractAccontauthenticator,以将服务器上的某些数据与内容提供商同步。

我做了所有内容,并且两个添加帐户和同步都没有任何问题。

现在,我尝试添加一个偏好屏幕,就像Android参考中的建议(搜索AbstractAccountauthenticator,在此处搜索在那里)通过XML这样的说明:

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

偏好屏幕-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>

屏幕是应该的,但是这就是问题:当我单击带有意图的首选项时,它会导致系统崩溃(在模拟器和我的HTC-Desire中)。

logcat说:

错误/androidruntime(18754):android.util.androidruntimeException:从活动上下文的外部调用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)

谢谢你的帮助,埃森蒂安

PS:KeyGen不是键的生成器,它意味着更多的key_general。有点表达;)

有帮助吗?

解决方案

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

<?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>

然后它按预期工作。这很奇怪,因为我希望偏爱将项目分组为孩子……为什么会导致如此无关的(?)错误?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top