小编Ese*_*ian的帖子

PreferenceScreen - <intent ... /> - 异常 - FLAG_ACTIVITY_NEW_TASK

我是android开发的新手.

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

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

现在我尝试添加一个Preference-Screen,就像在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"
 />
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

屏幕应该是它应该如何,但这就是问题:当我点击PreferenceScreen意图导致系统崩溃(在模拟器和我的HTC-Desire中).

Logcat说:

ERROR/AndroidRuntime(18754):android.util.AndroidRuntimeException:从Activity上下文外部调用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>
Run Code Online (Sandbox Code Playgroud)

整个测试代码(这是我找到问题的基本要点的项目)是在googlecode(http://code.google.com/p/cleanproject/source/browse/)上找到(Eclipse-Project)

谢谢你的帮助,Esentian

ps:keygen不是密钥生成器,它意味着更多key_general.有点不好意思;)

xml android exception account-management preferencescreen

6
推荐指数
1
解决办法
6645
查看次数