【问题标题】:PreferenceScreen - <intent .../> - Exception - FLAG_ACTIVITY_NEW_TASKPreferenceScreen - <intent .../> - 异常 - FLAG_ACTIVITY_NEW_TASK
【发布时间】:2010-09-16 13:42:06
【问题描述】:

我是 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: 从外部调用 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)上找到的

已经感谢您的帮助, 埃森蒂安

p.s.:keygen 不是密钥生成器,它意味着更多的 key_general。表达的有点拙劣;)

【问题讨论】:

    标签: android xml exception account-management preferencescreen


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回答!过去几周我搬到了一个新公寓,直到今天才下线。这个解决方案就像一个解决方法,但是谢谢你,现在一切都运行良好。
    • 该死的,哦,Android,只需删除 它终于可以工作了。非常感谢!
    • 它对我不起作用。如果 PreferenceScreen 在 PreferenceCategory 之外,则不会显示它。
    猜你喜欢
    • 1970-01-01
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多